- i18n_audit.py: 同步扫描 lang/<locale>/<module>.js 多文件 + lang/<locale>.js 单文件 - i18n_check_naming.py (新增): 检测中文 key / 扁平 key / 行号式 locational key / 跨业务域同名 / 非 snake_case - i18n_check.py: 加入 naming 子命令,默认全套审计包含 naming - vue.config.js: I18nGuardPlugin 增加 naming 阻断 - full_migrate_i18n.py: 标 DEPRECATED,文档说明其输出违反 CLAUDE.md 1.2 铁律 - diagnose_keys.py (新增): 定位 orphan 调用 key 背景:之前审计'假阳性通过',实际 6018 处违规;现在审计能看到真实状态。 Fix: docs/i18n-rules.md 1.6 条铁律需补强 (modular 审计入口已加) 统计 (i18n_check_naming.py 当前输出): A. 中文 key: 2146 B. 扁平 key: 188 C. 行号式 locational key: 1612 D. 跨业务域同名 tail: 1366 E. 非 snake_case key 段: 2924 TOTAL: 8236 处
70 lines
1.9 KiB
Python
70 lines
1.9 KiB
Python
#!/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()) |