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.

build: the Mac string tables keep translations the ports still use when the Mac stops using them

wquguru4c950a4ccbce
diff --git a/scripts/strings.py b/scripts/strings.py
index 197dbf1..caf58a4 100755
--- a/scripts/strings.py
+++ b/scripts/strings.py
@@ -9,6 +9,7 @@ Keys come from the compiler (-emit-localized-strings), so interpolations are exa
keys the app looks up ("已听到 %lld 句"). zh-Hans/Localizable.strings maps every key to itself:
the development region is English, so without it Chinese systems would fall back to English.
English plurals live in en.lproj/Localizable.stringsdict.
+The ports read these tables too: a key the Mac no longer uses stays while a port still uses it.
"""
import glob, json, os, re, subprocess, sys, tempfile
@@ -46,6 +47,23 @@ def code_keys():
return keys
+# Where each port's L("…") / LF("…") calls are, as its own scripts/strings.py reads them.
+PORTS = {"Windows": ["windows/src/**/*.cs"], "Android": ["android/app/src/**/*.kt", "android/core/src/**/*.kt"],
+ "Linux": ["linux/cicada/**/*.py"]}
+PORT_CALL = re.compile(r'\bLF?\("((?:[^"\\]|\\.)*)"')
+
+
+def port_keys():
+ keys = {}
+ for port, patterns in PORTS.items():
+ for pattern in patterns:
+ for f in sorted(glob.glob(os.path.join(ROOT, pattern), recursive=True)):
+ for k in PORT_CALL.findall(open(f, encoding="utf-8").read()):
+ k = re.sub(r"\\(.)", lambda m: "\n" if m.group(1) == "n" else m.group(1), k)
+ if CJK.search(k): keys.setdefault(k, set()).add(port)
+ return keys
+
+
def load(path):
if not os.path.exists(path):
return {}
@@ -68,12 +86,15 @@ def write(path, pairs):
def main():
keys = code_keys()
+ ports = port_keys()
bad = False
for lang in LANGS:
path = TABLE.format(lang)
table = load(path)
missing = [k for k in keys if k not in table]
- unused = [k for k in table if k not in keys]
+ unused = [k for k in table if k not in keys and k not in ports]
+ # Kept, translated, for the ports; anything they still lack their own scripts report.
+ kept = [(k, v, "Only the ports: " + ", ".join(sorted(ports[k]))) for k, v in table.items() if k not in keys and k in ports]
todo = [k for k, v in table.items() if v == "TODO"]
mismatch = [k for k, v in table.items() if v != "TODO" and specs(k) != specs(v)]
for k in missing: print(f"{lang} missing {keys[k]}: {k}")
@@ -81,7 +102,7 @@ def main():
for k in todo: print(f"{lang} todo {k}")
for k in mismatch: print(f"{lang} specifier {k} -> {table[k]}")
if "--write" in sys.argv:
- write(path, [(k, table.get(k, "TODO"), g) for k, g in keys.items()])
+ write(path, [(k, table.get(k, "TODO"), g) for k, g in keys.items()] + sorted(kept, key=lambda p: p[2]))
subprocess.run(["plutil", "-lint", "-s", path], check=True)
print(f"{lang}: {len(keys)} keys, {len(missing)} missing, {len(unused)} unused, {len(todo)} TODO, {len(mismatch)} bad specifiers")
bad |= bool(missing or todo or mismatch)