Skip to content

知了 Cicada · 任何会议和直播的实时字幕、同声传译、AI 会议纪要,Mac、Windows、Linux、Android 免费开源。Live subtitles, interpreting and meeting notes for any call or stream, on Mac, Windows, Linux and Android.

fix(windows): subtitles no longer show a lone "Translate" when Ling translates its own instruction instead of the line

wquguru224b2ede72fd
diff --git a/windows/src/Cicada.Core/Translator.cs b/windows/src/Cicada.Core/Translator.cs
index ff4f0b0..7088607 100644
--- a/windows/src/Cicada.Core/Translator.cs
+++ b/windows/src/Cicada.Core/Translator.cs
@@ -200,6 +200,12 @@ public sealed class Translator(LingClient ling, HttpMessageHandler? google = nul
return result.Length == 0 ? null : result;
}
+ /// "Translate." in each target language, letters only and lowercased. Port of instructionEchoes.
+ static readonly HashSet<string> InstructionEchoes = [
+ "翻译", "翻譯", "translate", "翻訳", "翻訳して", "翻訳する", "翻訳してください", "번역", "번역해", "번역하세요", "번역해주세요",
+ "traducir", "traduce", "traduzca", "traduire", "traduisez", "traduis", "übersetzen", "übersetze", "traduzir", "traduza",
+ ];
+
/// Ling sometimes comments on a garbled subtitle instead of translating it ("The subtitle
/// appears to be…"). Remark lines go, a "Translation:" label is stripped, and what is left must
/// be in the target's script; null lets the next provider try. Port of cleanTranslation.
@@ -234,6 +240,9 @@ public sealed class Translator(LingClient ling, HttpMessageHandler? google = nul
}
output = output.Trim();
if (output.Length == 0) return null;
+ // Ling translated the fixed "Translate." instruction instead of the subtitle ("翻译。" for an empty
+ // subtitle, or for "Translate this into Chinese please."); the next provider translates it.
+ if (InstructionEchoes.Contains(new string(output.ToLowerInvariant().Where(char.IsLetter).ToArray()))) return null;
return Languages.InScript(output, target) ? output : null;
}
}
diff --git a/windows/tests/Cicada.Tests/Program.cs b/windows/tests/Cicada.Tests/Program.cs
index 78092b6..e3a76e7 100644
--- a/windows/tests/Cicada.Tests/Program.cs
+++ b/windows/tests/Cicada.Tests/Program.cs
@@ -382,6 +382,9 @@ static class Tests
Equal("Hello", Translator.CleanTranslation("Here is the translation:\nHello", "en"), "remark line dropped");
Equal(null, Translator.CleanTranslation("请提供需要翻译的字幕内容", "en"), "a request for input is not a translation");
Equal(null, Translator.CleanTranslation("Hello", "zh-CN"), "wrong script");
+ Equal(null, Translator.CleanTranslation("翻译。", "zh-CN"), "the instruction translated, not the subtitle");
+ Equal(null, Translator.CleanTranslation("Translate.", "en"), "the instruction translated, in English");
+ Equal("好的,翻译。", Translator.CleanTranslation("好的,翻译。", "zh-CN"), "a sentence about translating is kept");
Equal("Done.", Translator.CleanTranslation("<think>x</think>Done.", "en"), "leaked reasoning");
}