#!/usr/bin/env python3 """ i18n_check.py - i18n 审计一键入口 用法: python scripts/i18n_check.py # 全部审计(audit + strict + class_c) python scripts/i18n_check.py basic # 只跑基础 audit python scripts/i18n_check.py strict # 跑 strict + class_c python scripts/i18n_check.py shadow # 只跑 class_c(page 覆盖 common) python scripts/i18n_check.py clean # 清理死 key(带 --apply 才会真删) 退出码: 0 = 通过 非 0 = 失败 设计为可以直接被 git hook / CI / 本地命令行任意调用。 """ import sys import subprocess from pathlib import Path ROOT = Path(__file__).resolve().parent.parent SCRIPTS = { 'basic': 'scripts/i18n_audit.py', 'strict': 'scripts/i18n_strict_audit.py', 'shadow': 'scripts/i18n_class_c.py', 'symmetry': 'scripts/i18n_check_symmetry.py', 'naming': 'scripts/i18n_check_naming.py', } def run(script_name): """Run a python audit script, return its exit code""" script_path = ROOT / SCRIPTS[script_name] if not script_path.exists(): print(f'[ERROR] {script_path} not found', file=sys.stderr) return 1 print(f'\n>> Running {script_name}: {script_path.relative_to(ROOT)}') result = subprocess.run( ['python', str(script_path)], cwd=str(ROOT), ) return result.returncode def main(): args = sys.argv[1:] if not args or args[0] == 'all': # Run all audits rc = 0 for name in ['basic', 'symmetry', 'strict', 'shadow', 'naming']: if run(name) != 0: rc = 1 print() if rc == 0: print('[OK] All i18n audits passed') else: print('[FAIL] i18n audits reported issues - see docs/i18n-*-audit.json') return rc if args[0] in SCRIPTS: return run(args[0]) print(__doc__) return 1 if __name__ == '__main__': sys.exit(main())