Repository Public
1#!/usr/bin/env python32# ORIX Docs3# File: Scripts/l10n.py4# Description: Builds App/Resources/Localizable.xcstrings from the strings the compiler extracted during the last build (*.stringsdata)5# and the Canadian French translations in Scripts/translations-fr-CA.json. Run after Scripts/build.sh.6# l10n.py keys prints the source keys (JSON) — the list to translate7# l10n.py build writes the catalog and reports coverage; exits 1 when a key has no translation8#9# Author: Simon-Pierre Boucher10# Contact: contact@spboucher.ai11import glob, json, os, sys1213ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))14DATA = os.path.join(ROOT, "build/DerivedData/Build/Intermediates.noindex/ORIXDocs.build/*/ORIXDocs.build/Objects-normal/*/*.stringsdata")15TRANSLATIONS = os.path.join(ROOT, "Scripts/translations-fr-CA.json")16CATALOG = os.path.join(ROOT, "App/Resources/Localizable.xcstrings")1718def keys():19 found = {}20 for path in glob.glob(DATA):21 try: data = json.load(open(path))22 except Exception: continue23 for table, entries in data.get("tables", {}).items():24 if table != "Localizable": continue25 for e in entries:26 k = e.get("key")27 if k and k.strip(): found.setdefault(k, e.get("comment") or "")28 return dict(sorted(found.items()))2930def main():31 mode = sys.argv[1] if len(sys.argv) > 1 else "build"32 ks = keys()33 if not ks: sys.exit("No extracted strings found: build the app first (Scripts/build.sh).")34 if mode == "keys":35 print(json.dumps(list(ks.keys()), ensure_ascii=False, indent=1)); return36 fr = json.load(open(TRANSLATIONS)) if os.path.exists(TRANSLATIONS) else {}37 strings, missing = {}, []38 for k in ks:39 entry = {}40 if k in fr and fr[k].strip():41 entry["localizations"] = {"fr-CA": {"stringUnit": {"state": "translated", "value": fr[k]}}}42 else:43 missing.append(k)44 strings[k] = entry45 json.dump({"sourceLanguage": "en", "strings": strings, "version": "1.0"}, open(CATALOG, "w"), ensure_ascii=False, indent=2, sort_keys=True)46 print(f"{len(ks)} keys, {len(ks) - len(missing)} translated to fr-CA, {len(missing)} missing")47 if missing:48 json.dump(missing, open(os.path.join(ROOT, "build/l10n-missing.json"), "w"), ensure_ascii=False, indent=1)49 print("missing keys written to build/l10n-missing.json"); sys.exit(1)5051main()52