Files
SlideWire/scripts/i18n-extract.py
T
NilsBriggenandClaude Opus 5.5 7cd5c1896d Translation groundwork: rust-i18n with English keys
t!("English text") looks the text up in locales/<lang>.json for the
desktop's language and falls back to English. scripts/i18n-extract.py
collects the keys into locales/en.json; a test fails when one is missing.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-11 20:05:29 +02:00

19 lines
810 B
Python
Executable File

#!/usr/bin/env python3
"""Collect every t!("...") key in src/ into locales/en.json (English: the key
is the text). Run after adding or changing user-visible strings; the test
`i18n::tests::every_key_is_in_en_json` fails until you do."""
import json, pathlib, re
root = pathlib.Path(__file__).resolve().parent.parent
# t!( but not format!( or print!(.
pattern = re.compile(r'(?:^|[^A-Za-z0-9_])t!\(\s*"((?:[^"\\]|\\.)*)"', re.M)
keys = set()
for f in sorted((root / "src").rglob("*.rs")):
for m in pattern.finditer(f.read_text()):
keys.add(json.loads(f'"{m.group(1)}"'))
out = {"_version": 1}
out.update({k: k for k in sorted(keys)})
path = root / "locales" / "en.json"
path.write_text(json.dumps(out, ensure_ascii=False, indent=1) + "\n")
print(f"{len(keys)} strings -> {path.relative_to(root)}")