Repository Public License
1#!/usr/bin/env python32# ORIX Audio3# File: Scripts/l10n.py4# Description: Builds the string catalogs from the compiler's extracted strings (.stringsdata) and Localization/fr-CA.json; reports untranslated keys.5#6# Author: Simon-Pierre Boucher7# Contact: contact@spboucher.ai8#9# usage: Scripts/l10n.py [--check] (run after a build: the .stringsdata files come from build/dd)10import glob, json, pathlib, sys11ROOT = pathlib.Path(__file__).resolve().parent.parent12TARGETS = {"ORIXAudio": ROOT / "ORIXAudio/Resources/Localizable.xcstrings", "ORIXAudioWidgets": ROOT / "ORIXAudioWidgets/Localizable.xcstrings"}13translations = json.loads((ROOT / "Localization/fr-CA.json").read_text()) if (ROOT / "Localization/fr-CA.json").exists() else {}14missing, total = [], 015for target, catalog in TARGETS.items():16 keys = {}17 for f in glob.glob(str(ROOT / f"build/dd/Build/Intermediates.noindex/ORIXAudio.build/*/{target}.build/Objects-normal/*/*.stringsdata")):18 for entry in json.load(open(f)).get("tables", {}).get("Localizable", []):19 keys.setdefault(entry["key"], entry.get("comment", ""))20 if not keys:21 sys.exit(f"no .stringsdata for {target}: build the app first (Scripts/build.sh)")22 strings = {}23 for key in sorted(keys):24 entry = {}25 if key in translations:26 entry["localizations"] = {"fr-CA": {"stringUnit": {"state": "translated", "value": translations[key]}}}27 elif key.strip() and any(c.isalpha() for c in key.replace("%@", "").replace("%lld", "").replace("%d", "")):28 missing.append(key)29 strings[key] = entry30 total += 131 if "--check" not in sys.argv:32 catalog.write_text(json.dumps({"sourceLanguage": "en", "strings": strings, "version": "1.0"}, ensure_ascii=False, indent=2, sort_keys=True) + "\n")33missing = sorted(set(missing))34(ROOT / "build/l10n-missing.json").write_text(json.dumps({k: "" for k in missing}, ensure_ascii=False, indent=1))35print(f"{total} keys, {len(missing)} without a fr-CA translation" + (" (list in build/l10n-missing.json)" if missing else ""))36sys.exit(1 if missing and "--check" in sys.argv else 0)37