i18n
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
Chinesei18n Audit
国际化(i18n)审计
Detection
检测
Read for i18n library:
package.json- /
react-i18nexti18next next-intlvue-i18n- (FormatJS)
react-intl
Read locale files to understand key structure (e.g. ).
src/locales/en.json读取文件识别i18n库:
package.json- /
react-i18nexti18next next-intlvue-i18n- (FormatJS)
react-intl
读取语言区域文件以了解键结构(例如)。
src/locales/en.jsonWorkflow
工作流程
- Detect i18n library and locale file locations
- Search JSX/TSX/Vue files for hardcoded user-facing strings (see patterns.md):
- String literals in JSX:
<p>Hello world</p> - String props: ,
placeholder="Search..."label="Submit" aria-label="Close menu"
- String literals in JSX:
- Compare locale files — find missing keys between locales:
bash
# keys in en.json but missing in pt.json - Report findings
- 检测i18n库和语言区域文件位置
- 在JSX/TSX/Vue文件中搜索面向用户的硬编码字符串(参见patterns.md):
- JSX中的字符串字面量:
<p>Hello world</p> - 字符串属性:,
placeholder="Search..."label="Submit" aria-label="Close menu"
- JSX中的字符串字面量:
- 对比语言区域文件——查找不同语言区域之间缺失的键:
bash
# keys in en.json but missing in pt.json - 报告发现结果
Output format
输出格式
Hardcoded strings ():
file:linesrc/components/Header.tsx:12 "Welcome back" → suggest key: header.welcomeBack
src/components/Form.tsx:34 placeholder="Search..." → suggest key: form.searchPlaceholderMissing translations (key present in base locale but absent in others):
Key: dashboard.emptyState missing in: pt-BR, es
Key: errors.networkTimeout missing in: pt-BR硬编码字符串():
文件:行号src/components/Header.tsx:12 "Welcome back" → suggest key: header.welcomeBack
src/components/Form.tsx:34 placeholder="Search..." → suggest key: form.searchPlaceholder缺失的翻译(基准语言区域存在但其他区域缺失的键):
Key: dashboard.emptyState missing in: pt-BR, es
Key: errors.networkTimeout missing in: pt-BRRules
规则
- Only flag user-visible strings (skip internal IDs, CSS classes, URLs, enum values)
- Suggest translation key names in camelCase matching project convention
- Never auto-modify locale files — report only
- 仅标记用户可见的字符串(跳过内部ID、CSS类、URL、枚举值)
- 建议符合项目约定的小驼峰式(camelCase)翻译键名称
- 绝不自动修改语言区域文件——仅作报告
Error Handling
错误处理
- If no i18n library detected → report project may not use i18n; still list any hardcoded strings found
- If no locale files found → skip missing-key comparison; only report hardcoded strings
- If locale files are not JSON (e.g. ,
.po) → read them anyway and adapt key comparison logic.yaml
- 如果未检测到i18n库→报告项目可能未使用i18n;仍列出所有找到的硬编码字符串
- 如果未找到语言区域文件→跳过键缺失对比;仅报告硬编码字符串
- 如果语言区域文件不是JSON格式(例如、
.po)→仍读取文件并调整键对比逻辑.yaml