Repository Public
1#!/usr/bin/env python32# SP Lecture Studio3# File: scripts/localize.py4# Description: Keeps the String Catalog in step with the code: syncs the keys extracted by the compiler (after a build) and applies5# the English translations from scripts/translations-en.json. Prints how many keys still lack a translation.6#7# Author: Simon-Pierre Boucher8# Contact: contact@spboucher.ai9import glob, json, os, subprocess, sys10root = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))11catalog = os.path.join(root, "Apps/LectureStudio/Resources/Localizable.xcstrings")12dd = os.environ.get("DERIVED_DATA", os.path.expanduser("~/Library/Developer/SPLectureStudio/DerivedData"))13data = [f for f in glob.glob(dd + "/Build/Intermediates.noindex/**/*.stringsdata", recursive=True)14 if ("LectureStudio-iOS.build" in f or "LectureStudio-macOS.build" in f)]15if data:16 args = ["xcrun", "xcstringstool", "sync", catalog]17 for f in data: args += ["--stringsdata", f]18 subprocess.run(args, check=True)19else:20 print("no .stringsdata found (build the apps first); applying translations only")21tr = json.load(open(os.path.join(root, "scripts/translations-en.json"), encoding="utf-8"))22cat = json.load(open(catalog, encoding="utf-8"))23missing = []24for key, entry in cat["strings"].items():25 if key in tr:26 entry.setdefault("localizations", {})["en"] = {"stringUnit": {"state": "translated", "value": tr[key]}}27 else:28 missing.append(key)29json.dump(cat, open(catalog, "w", encoding="utf-8"), ensure_ascii=False, indent=2, sort_keys=True)30print(f"{len(cat['strings'])} keys, {len(cat['strings']) - len(missing)} translated to English, {len(missing)} missing")31for k in missing[:40]: print(" MISSING:", k)32sys.exit(1 if missing and "--strict" in sys.argv else 0)33