feat(i18n): add full i18n audit toolchain and pre-commit hook
- 新增 GitHub Actions 工作流实现 PR 时自动审计国际化内容 - 添加 pre-commit 钩子,提交前自动检查相关文件并拦截问题提交 - 编写完整的 i18n 审计脚本、文档与示例报告 - 实现多维度国际化校验:键匹配、占位符、data()误用、硬编码标题等
This commit is contained in:
43
.husky/pre-commit
Normal file
43
.husky/pre-commit
Normal file
@@ -0,0 +1,43 @@
|
||||
#!/usr/bin/env sh
|
||||
#
|
||||
# 自动 hook:i18n 完整性。
|
||||
# 在 commit 前,如果改动触及 lang/、使用 $lang() 的 .vue/.js,或 lang-bundle.json,
|
||||
# 就跑一次审计,真问题会拦下 commit。
|
||||
#
|
||||
# 启用方法:
|
||||
# 1) 项目根已有 .husky/pre-commit(本脚本)
|
||||
# 2) 把这个 commit-msg / pre-commit 加入 husky 钩子(本仓库用 simple-git-hooks
|
||||
# 或 husky 都行,本脚本不依赖特定框架)
|
||||
#
|
||||
# 也可以在 CI 跑:
|
||||
# python scripts/i18n_audit.py --strict
|
||||
|
||||
set -e
|
||||
|
||||
# 检测本次 diff 是否触动相关文件
|
||||
changed=$(git diff --cached --name-only HEAD)
|
||||
|
||||
relevant=$(echo "$changed" | grep -E '(lang/|lang-bundle\.json|\.vue$|\.js$)' | grep -v 'scripts/i18n_audit\|scripts/audit\|scripts/I18N_AUDIT' || true)
|
||||
|
||||
if [ -z "$relevant" ]; then
|
||||
echo "[pre-commit] No lang-touching files; skip i18n audit."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
echo "[pre-commit] Running i18n audit on changed files:"
|
||||
echo "$relevant" | sed 's/^/ /'
|
||||
|
||||
cd "$(git rev-parse --show-toplevel)"
|
||||
|
||||
if command -v python >/dev/null 2>&1; then
|
||||
if python scripts/i18n_audit.py --strict; then
|
||||
echo "[pre-commit] i18n OK"
|
||||
exit 0
|
||||
else
|
||||
echo "[pre-commit] i18n FAILED — 修复方法见 scripts/I18N_AUDIT.md"
|
||||
exit 1
|
||||
fi
|
||||
else
|
||||
echo "[pre-commit] python not available; skipping"
|
||||
exit 0
|
||||
fi
|
||||
Reference in New Issue
Block a user