SPB Git

Repository Public

strings.py 2.0 KB 38 lines python

1#!/usr/bin/env python32# SP Chat iOS3# File: Scripts/strings.py4# Description: Keeps Localizable.xcstrings in step with the code after a Debug build: adds the new French source strings5#              (xcstringstool sync over the build's .stringsdata), drops the ones no longer used, merges English6#              translations from a JSON file {key: english} when given, and lists what still lacks English.7#              usage: strings.py [translations.json]8#9# Author: Simon-Pierre Boucher10# Contact: contact@spboucher.ai11import json12import subprocess13import sys14from pathlib import Path1516ROOT = Path(__file__).resolve().parent.parent17CATALOG = ROOT / "SPChat-iOS" / "Resources" / "Localizable.xcstrings"18DATA = sorted((ROOT / "build" / "DerivedData" / "Build" / "Intermediates.noindex" / "SPChat.build" / "Debug-iphonesimulator" / "SPChat.build").rglob("*.stringsdata"))19if not DATA:20    sys.exit("aucun .stringsdata : lancer d'abord Scripts/build.sh debug")21subprocess.run(["xcrun", "xcstringstool", "sync", str(CATALOG), "--stringsdata", *map(str, DATA)], check=True)22catalog = json.loads(CATALOG.read_text(encoding="utf-8"))23strings = catalog["strings"]24stale = [k for k, v in strings.items() if v.get("extractionState") == "stale"]25for k in stale:26    del strings[k]27merged = 028if len(sys.argv) > 1:29    for key, english in json.loads(Path(sys.argv[1]).read_text(encoding="utf-8")).items():30        if key in strings and "en" not in strings[key].get("localizations", {}):31            strings[key].setdefault("localizations", {})["en"] = {"stringUnit": {"state": "translated", "value": english}}32            merged += 133missing = [k for k, v in strings.items() if "en" not in v.get("localizations", {})]34CATALOG.write_text(json.dumps(catalog, ensure_ascii=False, indent=2, sort_keys=True, separators=(",", " : ")) + "\n", encoding="utf-8")35print(f"{len(strings)} chaînes ; {len(stale)} retirées ; {merged} traductions ajoutées ; {len(missing)} sans anglais")36for k in missing:37    print("  " + json.dumps(k, ensure_ascii=False))38
Files main
Menu

Theme