#!/usr/bin/env python3 """Keep the string catalog whole and in Equipo's voice. scripts/strings.json is the English source, reviewed by Paul on 2026-11-19; new or changed strings are draft until reviewed. This writes it into the String Catalog with --write, and checks: every key the Swift sources use has English text, no text has an em dash or an exclamation mark, and the catalog matches strings.json.""" import json, re, sys from pathlib import Path native = Path(__file__).resolve().parents[1] source = json.loads((native / 'scripts/strings.json').read_text()) # EquipoKit's catalog, and the same words for EquipoActivity, which the # iPhone's widget extension draws the Live Activity with on its own. catalog_paths = [native / 'apple/Sources' / target / 'Resources/Localizable.xcstrings' for target in ('EquipoKit', 'EquipoActivity')] catalog_paths.append(native / 'share/Sources/EquipoShareUI/Resources/Localizable.xcstrings') plurals = json.loads((native / 'scripts/plurals.json').read_text()) def catalog(): return {'sourceLanguage': 'en', 'version': '1.0', 'strings': { k: {**({'comment': ('COPY APPROVED: Luna, 2026-11-27.' if k == 'native.share.earlier_unconfirmed' or k.startswith('native.mac.') else 'COPY APPROVED: Luna, 2026-11-26.')} if k.startswith(('native.diff.', 'native.changes.', 'native.share.', 'native.screenshot.', 'native.mac.')) or k in ('api.preview_changed', 'api.preview_expired') else {}), 'extractionState': 'manual', 'localizations': {'en': plurals.get(k, {'stringUnit': {'state': 'translated', 'value': v}})}} for k, v in sorted(source.items())}} def used_keys(): keys = set() for f in [*(native / 'apple/Sources').rglob('*.swift'), *(native / 'share/Sources').rglob('*.swift')]: text = f.read_text() for m in re.finditer(r'(?:String\(localized:|(?:EquipoStrings|ShareWords)\.text\()\s*"((?:[^"\\]|\\.|\\\([^)]*\))*)"', text): raw = m.group(1) # Interpolations become format specifiers: Int as %lld, the rest %@. # A count (count, x.count, $0.count) is an Int. raw = re.sub(r'\\\((?:[\w$]+\.)?count\)', '%lld', raw) raw = re.sub(r'\\\((?:[^()]|\([^()]*\))*\)', '%@', raw) keys.add(raw) return keys problems = [] # The plural catalog's ordinary forms must stay identical to the reviewed # English source. Singular forms are exercised by native localization tests. for key, value in plurals.items(): ordinary = value['stringUnit']['value'] for name, substitution in value['substitutions'].items(): ordinary = ordinary.replace('%#@' + name + '@', substitution['variations']['plural']['other']['stringUnit']['value']) ordinary = re.sub(r'%[0-9]+\$', '%', ordinary) if ordinary != source.get(key): problems.append(f'{key}: plural catalog differs from reviewed source') for match in re.findall(r'"value": "([^"]*)"', json.dumps(value, ensure_ascii=False)): if '—' in match or '!' in match: problems.append(f'{key}: unreviewed punctuation in plural form') for k in sorted(used_keys() - source.keys()): problems.append(f'no English text for key: {k}') for k, v in source.items(): if '—' in v: problems.append(f'em dash in {k}') if '!' in v: problems.append(f'exclamation mark in {k}') for catalog_path in catalog_paths: if '--write' in sys.argv: catalog_path.write_text(json.dumps(catalog(), indent=2, ensure_ascii=False) + '\n') elif not catalog_path.is_file() or json.loads(catalog_path.read_text()) != catalog(): problems.append(f'{catalog_path.relative_to(native)} is out of date: run native/scripts/check-strings.py --write') for p in problems: print(p) if problems: sys.exit(1) # Facts look their words up by a key made from the wire value # (TaskReport.facts); FactWordsTests checks each one resolves. computed = {k for k in source if k.startswith(('checks.', 'review.', 'chat.card.', 'work.tl.', 'work.reason.', 'work.needs.'))} unused = sorted(source.keys() - used_keys() - computed) print(f'{len(source)} strings, all used keys present' + (f'; unused: {unused}' if unused else ''))