1
0
mirror of https://github.com/AvengeMedia/DankMaterialShell.git synced 2026-08-02 03:28:28 -04:00

i18n: add mechanism for blocking new terms

This commit is contained in:
bbedward
2026-07-04 16:51:28 -04:00
parent fd99558ce5
commit 57a04cf409
3 changed files with 3145 additions and 0 deletions
@@ -0,0 +1,50 @@
#!/usr/bin/env python3
"""Enforce the i18n term freeze.
While term_freeze.json exists, any I18n.tr()/qsTr() term not in it fails the check.
Existing terms may be reused or moved freely.
--update re-snapshot the current terms into term_freeze.json
(delete term_freeze.json to lift the freeze)
"""
import json
import sys
from pathlib import Path
from extract_translations import extract_qstr_strings
SCRIPT_DIR = Path(__file__).parent
ROOT_DIR = SCRIPT_DIR.parent
FREEZE_FILE = SCRIPT_DIR / 'term_freeze.json'
def main():
if '--update' in sys.argv:
translations = extract_qstr_strings(ROOT_DIR)
FREEZE_FILE.write_text(json.dumps(sorted(translations), indent=2, ensure_ascii=False) + '\n', encoding='utf-8')
print(f"Froze {len(translations)} terms to {FREEZE_FILE}")
return 0
if not FREEZE_FILE.exists():
print("i18n term freeze inactive (term_freeze.json not present)")
return 0
frozen = set(json.loads(FREEZE_FILE.read_text(encoding='utf-8')))
translations = extract_qstr_strings(ROOT_DIR)
new_terms = sorted(term for term in translations if term not in frozen)
if not new_terms:
return 0
print(f"i18n term freeze: {len(new_terms)} new term(s) introduced:", file=sys.stderr)
for term in new_terms:
print(f'\n "{term}"', file=sys.stderr)
for occ in translations[term]['occurrences']:
print(f" quickshell/{occ['file']}:{occ['line']}", file=sys.stderr)
print("\nReuse an existing term instead. To intentionally allow new terms, run", file=sys.stderr)
print(" python3 quickshell/translations/check_term_freeze.py --update", file=sys.stderr)
print("and stage term_freeze.json. Delete term_freeze.json to lift the freeze entirely.", file=sys.stderr)
return 1
if __name__ == '__main__':
sys.exit(main())
File diff suppressed because it is too large Load Diff