i18n

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

i18n Audit

国际化(i18n)审计

Detection

检测

Read
package.json
for i18n library:
  • react-i18next
    /
    i18next
  • next-intl
  • vue-i18n
  • react-intl
    (FormatJS)
Read locale files to understand key structure (e.g.
src/locales/en.json
).
读取
package.json
文件识别i18n库:
  • react-i18next
    /
    i18next
  • next-intl
  • vue-i18n
  • react-intl
    (FormatJS)
读取语言区域文件以了解键结构(例如
src/locales/en.json
)。

Workflow

工作流程

  1. Detect i18n library and locale file locations
  2. 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"
  3. Compare locale files — find missing keys between locales:
    bash
    # keys in en.json but missing in pt.json
  4. Report findings
  1. 检测i18n库和语言区域文件位置
  2. 在JSX/TSX/Vue文件中搜索面向用户的硬编码字符串(参见patterns.md):
    • JSX中的字符串字面量:
      <p>Hello world</p>
    • 字符串属性:
      placeholder="Search..."
      ,
      label="Submit"
    • aria-label="Close menu"
  3. 对比语言区域文件——查找不同语言区域之间缺失的键:
    bash
    # keys in en.json but missing in pt.json
  4. 报告发现结果

Output format

输出格式

Hardcoded strings (
file:line
):
src/components/Header.tsx:12  "Welcome back"  → suggest key: header.welcomeBack
src/components/Form.tsx:34    placeholder="Search..."  → suggest key: form.searchPlaceholder
Missing 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-BR

Rules

规则

  • 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
    ,
    .yaml
    ) → read them anyway and adapt key comparison logic
  • 如果未检测到i18n库→报告项目可能未使用i18n;仍列出所有找到的硬编码字符串
  • 如果未找到语言区域文件→跳过键缺失对比;仅报告硬编码字符串
  • 如果语言区域文件不是JSON格式(例如
    .po
    .yaml
    )→仍读取文件并调整键对比逻辑