| name | i18n-check |
| description | 检查并补充前端和后端的i18n翻译文件。以中文(zh-CN)为基准,检查其他语言翻译文件是否缺少key,并补充缺失的key和对应的翻译值。对于日语(ja-JP)、韩语(ko-KR)、繁体中文(zh-TW),使用与非CJK语言对比的方式检测未翻译内容。 |
i18n 翻译检查与补充
快速开始(推荐安全用法)
强制前提:先用 Git 保证当前工作区是干净的(或至少 locales 相关改动可回滚),再运行下面任何脚本。
-
只在必要范围格式化翻译文件(建议从后端/英文开始)
python .cursor/skills/i18n-check/scripts/format_frontend.py
python .cursor/skills/i18n-check/scripts/format_backend.py
format_frontend.py 会重写所有 frontend/src/locales/*.ts:
- 仅做语法级重排与缩进,不再对字符做任何再编码;
- 仍然建议:先只在当前分支本地运行,确认 diff 可接受后再提交。
-
对比翻译差异(只读,不改文件):
python .cursor/skills/i18n-check/scripts/compare_frontend.py
python .cursor/skills/i18n-check/scripts/compare_backend.py
-
补全缺失的 key(使用中文作为占位符)
- 推荐做法:先只对英文和后端补全,再视情况扩展到其他语言。
python .cursor/skills/i18n-check/scripts/fill_frontend.py --target en-US
python .cursor/skills/i18n-check/scripts/fill_frontend.py
python .cursor/skills/i18n-check/scripts/fill_backend.py
-
AI 翻译(自动检测需要翻译的内容,不会直接改 TS/JSON 文件)
python .cursor/skills/i18n-check/scripts/translate_with_ai.py --target en-US
python .cursor/skills/i18n-check/scripts/translate_with_ai.py --all --cjk
-
CJK 语言翻译后检测(翻译完成后检查是否还有未翻译)
python .cursor/skills/i18n-check/scripts/export_translations.py --target ja-JP --cjk
python .cursor/skills/i18n-check/scripts/fill_frontend.py --check-cjk
完整工作流程(推荐顺序)
python .cursor/skills/i18n-check/scripts/format_frontend.py
python .cursor/skills/i18n-check/scripts/format_backend.py
python .cursor/skills/i18n-check/scripts/compare_frontend.py
python .cursor/skills/i18n-check/scripts/compare_backend.py
python .cursor/skills/i18n-check/scripts/fill_frontend.py --target en-US
python .cursor/skills/i18n-check/scripts/fill_backend.py
python .cursor/skills/i18n-check/scripts/translate_with_ai.py --all
python .cursor/skills/i18n-check/scripts/fill_frontend.py --check-cjk
python .cursor/skills/i18n-check/scripts/translate_with_ai.py --cjk
python .cursor/skills/i18n-check/scripts/export_translations.py --target ja-JP --cjk
python .cursor/skills/i18n-check/scripts/import_translations.py --file translation_export_ja-JP.txt
脚本说明
脚本位置
所有脚本位于 .cursor/skills/i18n-check/scripts/ 目录:
| 脚本 | 用途 |
|---|
format_frontend.py | 格式化前端 TS 翻译文件 |
compare_frontend.py | 对比前端翻译差异,支持 --cjk 检测 CJK 语言 |
fill_frontend.py | 补全前端缺失的 key,支持 --check-cjk 检测 CJK 未翻译 |
translate_with_ai.py | AI 翻译:自动检测需要翻译的内容并生成翻译提示,支持 --cjk |
export_translations.py | 导出未翻译内容到文本文件,支持 --cjk |
import_translations.py | 导入翻译结果 |
format_backend.py | 格式化后端 JSON 翻译文件 |
compare_backend.py | 对比后端翻译差异 |
fill_backend.py | 补全后端缺失的 key |
使用示例
对比 CJK 语言
python compare_frontend.py --target ja-JP --cjk
python compare_frontend.py --cjk-only
填充 CJK 语言
python fill_frontend.py --cjk
python fill_frontend.py --check-cjk
AI 翻译脚本
python translate_with_ai.py --type frontend --target en-US
python translate_with_ai.py --target ja-JP --cjk
python translate_with_ai.py --all --cjk
导出翻译
python export_translations.py --target ja-JP --cjk
翻译检测逻辑
- 非 CJK 语言 (en-US, de-DE, fr-FR 等): 检测含有中文的 key,需要翻译
- CJK 语言 (zh-TW, ja-JP, ko-KR): 检测与非 CJK 语言(如 en-US)相同的 key,需要翻译成对应语言
CJK 语言特殊处理
对于日语 (ja-JP)、韩语 (ko-KR)、繁体中文 (zh-TW),采用以下检测逻辑:
- 对比方式: 不以 zh-CN 为基准,而是与英语等非 CJK 语言对比
- 检测原理: 如果某个 key 在目标语言中的值与英语相同,说明该 key 未翻译
- 导出格式: 显示 baseline(中文) | reference(英语) | current(当前值),便于翻译
AI 翻译流程
- 运行
translate_with_ai.py 脚本
- 脚本会自动:
- 读取目标语言文件
- 检测需要翻译的中文内容(或 CJK 未翻译内容)
- 生成 AI 翻译提示 (prompt)
- 将生成的提示复制给 AI 进行翻译
- AI 返回 JSON 格式的翻译结果
- 使用
import_translations.py 导入翻译结果
文件位置
| 类型 | 目录 | 格式 | 基准文件 | CJK 基准文件 |
|---|
| 前端 | frontend/src/locales/ | TypeScript .ts | zh-CN.ts | en-US.ts |
| 后端 | internal/services/i18n/locales/ | JSON .json | zh-CN.json | en-US.json |
注意事项
- 保持 key 结构: 必须与基准文件完全一致,使用相同的嵌套层级
- 不要删除任何内容: 只能添加缺失的 key,不能删除现有的 key
- 变量占位符: 后端 JSON 使用
{{.xxx}} 格式,前端使用 {xxx} 格式,必须保留
- 格式化后再对比: 每次对比前先运行格式化脚本,确保格式统一
- CJK 语言处理: 繁体中文(zh-TW)、日语(ja-JP)、韩语(ko-KR)使用英语(en-US)作为基准文件进行对比和填充