- 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 处
44 lines
1.2 KiB
Python
44 lines
1.2 KiB
Python
#!/usr/bin/env python3
|
|
"""诊断: 哪些 $lang() 调用的 key 在哪能找到"""
|
|
import re
|
|
from pathlib import Path
|
|
|
|
ROOT = Path('.')
|
|
|
|
call_keys = set()
|
|
for f in ROOT.rglob('*.vue'):
|
|
sp = str(f)
|
|
if 'unpackage' in sp or 'node_modules' in sp:
|
|
continue
|
|
try:
|
|
text = f.read_text(encoding='utf-8')
|
|
except UnicodeDecodeError:
|
|
continue
|
|
for m in re.finditer(r'\$lang\(\s*["\']([^"\']+)["\']', text):
|
|
call_keys.add(m.group(1))
|
|
|
|
print(f'所有 $lang() 调用 key: {len(call_keys)} 个')
|
|
|
|
single = (ROOT / 'lang' / 'zh-cn.js').read_text(encoding='utf-8')
|
|
in_single = set()
|
|
for k in call_keys:
|
|
if f'"{k}":' in single:
|
|
in_single.add(k)
|
|
print(f' 在 lang/zh-cn.js 单文件里: {len(in_single)}')
|
|
|
|
modular = set()
|
|
for f in (ROOT / 'lang' / 'zh-cn').glob('*.js'):
|
|
if f.name == 'index.js':
|
|
continue
|
|
text = f.read_text(encoding='utf-8')
|
|
for k in call_keys:
|
|
leaf = k.split('.')[-1]
|
|
if f'"{leaf}"' in text or f'"{k}"' in text:
|
|
modular.add(k)
|
|
print(f' 在 lang/zh-cn/ modular 文件里: {len(modular)}')
|
|
|
|
orphan = call_keys - in_single - modular
|
|
print(f' 都不在 (orphan 调用): {len(orphan)}')
|
|
if orphan:
|
|
for k in sorted(orphan)[:10]:
|
|
print(f' - {k}') |