知了 Cicada · 任何会议和直播的实时字幕、同声传译、AI 会议纪要,Mac、Windows、Linux、Android 免费开源。Live subtitles, interpreting and meeting notes for any call or stream, on Mac, Windows, Linux and Android.
Swift androidlinuxlive-captionsmacosmeeting-notesmenubar-appsimultaneous-interpretationspeech-recognitionsubtitlesswiftswiftuitranslationwindows
fix(linux): in English, a meeting with one line says 1 line, not 1 lines
wqugurube9fa796a41d
diff --git a/linux/cicada/app/records_window.py b/linux/cicada/app/records_window.pyindex a16b254..4ac2bed 100644--- a/linux/cicada/app/records_window.py+++ b/linux/cicada/app/records_window.py@@ -729,8 +729,8 @@ class RecordsWindow(Gtk.Window):langs = " · " + (lang_name(src) if src == dst else lang_name(src) + " → " + lang_name(dst))# Heard through a microphone in the room, and with the computer's audio too: as on the Mac.place = " · " + (L("电脑和会议室") if roommic.heard_both(s.lines) else L("会议室")) if s.room else ""- return "%s · %s · %d %s%s%s" % (session_store._local_date(s.startedAt, L("M月d日 HH:mm")), L("正在听") if live else clock(s.duration),- len(s.lines), L("句"), langs, place)+ return "%s · %s · %s%s%s" % (session_store._local_date(s.startedAt, L("M月d日 HH:mm")), L("正在听") if live else clock(s.duration),+ LF("%lld 句", len(s.lines)), langs, place)def _notes_state(self, s, live):return (id(s.notes), s.notes.updatedAt if s.notes else None, self.app.notes.working_id == s.id, live)diff --git a/linux/cicada/app/tray.py b/linux/cicada/app/tray.pyindex 92986ca..fe042af 100644--- a/linux/cicada/app/tray.py+++ b/linux/cicada/app/tray.py@@ -143,7 +143,7 @@ class Tray:s = self.app.store.get(self.app.listen.session_id) if self.app.listen.session_id else Noneif s is None:return ""- return "%s · %d %s" % (session_store.display_title(s), len(s.lines), L("句"))+ return LF("%@ · %lld 句", session_store.display_title(s), len(s.lines))def tick(self) -> None:"""Once a second while listening: the clock in the top bar and the menu's header."""diff --git a/linux/cicada/core/strings.py b/linux/cicada/core/strings.pyindex b5baab4..9f2061a 100644--- a/linux/cicada/core/strings.py+++ b/linux/cicada/core/strings.py@@ -1,19 +1,22 @@"""UI text. The Chinese text is the key, as on the Mac, and the translations are the Mac's own`Resources/{en,ja,ko}.lproj/Localizable.strings`, plus `Linux.strings` (linux/strings/<lang>.lproj)-for text only the Linux app has. Placeholders are the Mac's `%@`, filled in order (or `%1$@`).-Never for prompts, logs or stored values."""+for text only the Linux app has, and the Mac's `Localizable.stringsdict` for plurals ("1 line",+"2 lines"). Placeholders are the Mac's `%@`, filled in order (or `%1$@`). Never for prompts, logs or+stored values."""from __future__ import annotationsimport os+import plistlib_table: dict = {}+_plurals: dict = {}language = "zh-Hans"def load(ui: str, folders: list) -> None:"""Loads the table for `ui` ("en", "ja", "ko"; anything else is Chinese) from each folder's<lang>.lproj/{Localizable,Linux}.strings, later folders over earlier ones."""- global _table, language+ global _table, _plurals, languagehead = ui.replace("_", "-").split("-")[0]language = head if head in ("en", "ja", "ko") else "zh-Hans"t: dict = {}@@ -24,6 +27,24 @@ def load(ui: str, folders: list) -> None:with open(path, encoding="utf-8") as f:t.update(parse(f.read()))_table = t+ _plurals = {}+ for folder in folders:+ path = os.path.join(folder, language + ".lproj", "Localizable.stringsdict")+ if os.path.isfile(path):+ with open(path, "rb") as f:+ _plurals.update(parse_plurals(f.read()))+++def parse_plurals(data: bytes) -> dict:+ """The Mac's Localizable.stringsdict: key → {"NSStringLocalizedFormatKey": format, variable →+ {"one": …, "other": …}}."""+ d = plistlib.loads(data)+ return {k: v for k, v in d.items() if isinstance(v, dict) and isinstance(v.get("NSStringLocalizedFormatKey"), str)}+++def _category(n) -> str:+ # Only English has more than one form among the app's languages: "one" for exactly 1.+ return "one" if language == "en" and isinstance(n, (int, float)) and n == 1 else "other"def L(key: str) -> str:@@ -32,12 +53,28 @@ def L(key: str) -> str:def LF(key: str, *args) -> str:- """L() with the Mac's `%@` placeholders, filled in order."""- text = L(key)+ """L() with the Mac's `%@` placeholders, filled in order. A key in the stringsdict takes its+ plural form for the number: `%#@n@` (or `%2$#@n@`) becomes variable n's "one" or "other" text."""+ plural = _plurals.get(key)+ text = plural["NSStringLocalizedFormatKey"] if plural else L(key)out = []nxt = 0i = 0while i < len(text):+ if plural and text[i] == "%":+ j, pos = i + 1, None+ if j + 1 < len(text) and text[j].isdigit() and text[j + 1] == "$":+ pos, j = int(text[j]) - 1, j + 2+ end = text.find("@", j + 2) if text.startswith("#@", j) else -1+ if end > 0:+ if pos is None:+ pos, nxt = nxt, nxt + 1+ n = args[pos] if 0 <= pos < len(args) else ""+ forms = plural.get(text[j + 2:end]) or {}+ form = forms.get(_category(n)) or forms.get("other", "")+ out.append(form.replace("%lld", str(n)).replace("%ld", str(n)).replace("%d", str(n)))+ i = end + 1+ continue# %@, and the Mac's numbers (%lld, %d) the same way: the Mac keys 说话人 N as "说话人 %lld".if text.startswith("%%", i): # a literal %, as in the Mac's "%lld%%"out.append("%")diff --git a/linux/scripts/build.sh b/linux/scripts/build.shindex 77a5ee3..c4c0dda 100755--- a/linux/scripts/build.sh+++ b/linux/scripts/build.sh@@ -1,7 +1,7 @@#!/bin/bash# Builds the installable tree build/cicada-linux/ and build/cicada-linux-<version>.tar.gz: the Python-# package, the strings tables (the Mac's Localizable.strings plus Linux.strings), the sample meeting-# as 16 kHz WAV, the menu entry, the icon and install.sh. Runs on the Mac or on Linux.+# package, the strings tables (the Mac's Localizable.strings and .stringsdict, plus Linux.strings),+# the sample meeting as 16 kHz WAV, the menu entry, the icon and install.sh. Runs on the Mac or on Linux.set -euo pipefailhere="$(cd "$(dirname "$0")/.." && pwd)"root="$(dirname "$here")"@@ -12,6 +12,7 @@ rsync -a --exclude __pycache__ "$here/cicada" "$out/"for lang in zh-Hans en ja ko; domkdir -p "$out/lproj/$lang.lproj"cp "$root/Resources/$lang.lproj/Localizable.strings" "$out/lproj/$lang.lproj/"+ [ -f "$root/Resources/$lang.lproj/Localizable.stringsdict" ] && cp "$root/Resources/$lang.lproj/Localizable.stringsdict" "$out/lproj/$lang.lproj/"[ -f "$here/strings/$lang.lproj/Linux.strings" ] && cp "$here/strings/$lang.lproj/Linux.strings" "$out/lproj/$lang.lproj/"donemkdir -p "$out/bin" && cp "$here/bin/cicada" "$out/bin/"diff --git a/linux/strings/en.lproj/Linux.strings b/linux/strings/en.lproj/Linux.stringsindex 00a786a..59b4101 100644--- a/linux/strings/en.lproj/Linux.strings+++ b/linux/strings/en.lproj/Linux.strings@@ -2,7 +2,6 @@"等有人说话" = "Waiting for someone to speak";"识别、翻译和纪要都靠它,约 1 分钟。" = "Recognition, translation and notes all run on it. About a minute.";"播放示例" = "Play sample";-"句" = "lines";"重命名" = "Rename";"保存失败" = "Couldn't save";"只存在这台电脑上(只有你的账户能读),只发给 Ling(ant-ling.com)" = "Stored only on this computer (readable only by your account) and sent only to Ling (ant-ling.com)";diff --git a/linux/strings/ja.lproj/Linux.strings b/linux/strings/ja.lproj/Linux.stringsindex 987d73f..af5904a 100644--- a/linux/strings/ja.lproj/Linux.strings+++ b/linux/strings/ja.lproj/Linux.strings@@ -2,7 +2,6 @@"等有人说话" = "誰かが話すのを待っています";"识别、翻译和纪要都靠它,约 1 分钟。" = "認識・翻訳・メモはすべてこれで動きます。約 1 分。";"播放示例" = "サンプルを再生";-"句" = "件";"重命名" = "名前を変更";"保存失败" = "保存できませんでした";"只存在这台电脑上(只有你的账户能读),只发给 Ling(ant-ling.com)" = "このコンピュータにのみ保存され(あなたのアカウントだけが読めます)、Ling(ant-ling.com)にのみ送信されます";diff --git a/linux/strings/ko.lproj/Linux.strings b/linux/strings/ko.lproj/Linux.stringsindex 1c0e01c..0b8b26c 100644--- a/linux/strings/ko.lproj/Linux.strings+++ b/linux/strings/ko.lproj/Linux.strings@@ -2,7 +2,6 @@"等有人说话" = "누군가 말하기를 기다리는 중";"识别、翻译和纪要都靠它,约 1 分钟。" = "인식, 번역, 노트 모두 이것으로 동작합니다. 약 1분.";"播放示例" = "샘플 재생";-"句" = "줄";"重命名" = "이름 바꾸기";"保存失败" = "저장하지 못했습니다";"只存在这台电脑上(只有你的账户能读),只发给 Ling(ant-ling.com)" = "이 컴퓨터에만 저장되며(내 계정만 읽을 수 있음) Ling(ant-ling.com)에만 전송됩니다";diff --git a/linux/tests/test_core.py b/linux/tests/test_core.pyindex d896e03..ee5bd59 100644--- a/linux/tests/test_core.py+++ b/linux/tests/test_core.py@@ -841,6 +841,24 @@ class Notes(Base):class Strings(Base):+ def test_plurals_from_the_macs_stringsdict(self):+ res = [os.path.join(REPO, "Resources"), os.path.join(REPO, "linux", "strings")]+ try:+ strings.load("en", res)+ self.assertEqual("1 line", strings.LF("%lld 句", 1))+ self.assertEqual("2 lines", strings.LF("%lld 句", 2))+ self.assertEqual("0 lines", strings.LF("%lld 句", 0))+ self.assertEqual("Heard 1 line", strings.LF("已听到 %lld 句", 1))+ self.assertEqual("Standup · 1 line", strings.LF("%@ · %lld 句", "Standup", 1)) # positional %2$#@n@+ self.assertEqual("Recorded 03:15 · 7 lines. Ending stops listening and writes the full notes.",+ strings.LF("已记录 %@ · %lld 句。结束后停止收听,并整理一份完整版纪要。", "03:15", 7))+ self.assertEqual("1 line", strings.LF("说了 %lld 句", 1))+ self.assertEqual("Live notes", strings.L("实时纪要"))+ strings.load("ja", res)+ self.assertEqual("1文", strings.LF("%lld 句", 1)) # no stringsdict: the .strings value+ finally:+ strings.load("zh-Hans", res)+def test_loads_the_macs_translations(self):res = [os.path.join(REPO, "Resources"), os.path.join(REPO, "linux", "strings")]strings.load("en_US.UTF-8", res)@@ -848,6 +866,7 @@ class Strings(Base):self.assertEqual("没有这条", strings.L("没有这条"))strings.load("zh-Hans", res)self.assertEqual("实时纪要", strings.L("实时纪要"))+ self.assertEqual("1 句", strings.LF("%lld 句", 1))t = strings.parse('/* c */\n"a \\"b\\"" = "x\\ny";\n// line\n"%@ 分钟" = "%@ min";')self.assertEqual("x\ny", t['a "b"'])self.assertEqual("%@ min", t["%@ 分钟"])