Skip to main content
Open Source CLI Tool

i18n Validator

检查翻译文件中的缺失键、损坏的占位符和复数不一致。一条命令,9 项检查,32 种格式,零配置。

9 checks 32 formats Zero config Native Rust binary

问题

用户遇到翻译问题前,问题一直不可见。键缺失时会显示 "settings.billing.title" 等原始路径,而不是真实文本;占位符损坏时会把 "{price}" 显示成文字,而不是 "9.99 美元";复数格式错误时,计数为零就会崩溃。这些缺陷会绕过代码审核,因为没人会手动比较 15 个本地化文件。

🔑

Missing keys

Blank text or key paths shown to users

🔗

Broken placeholders

{price} displays as literal text instead of $9.99

📁

Orphaned files

Outdated translations confuse the build system

💥

Malformed files

Runtime crashes when users switch languages

大多数验证工具只支持特定格式(仅 JSON 或仅 YAML),而且每个项目都要编写自定义测试代码。翻译缺陷往往到运行时才被发现,此时用户已经看到损坏的 UI。

解决方案

i18n-validate 一次扫描所有翻译文件。它会自动检测目录布局和文件格式,将每种语言与参考语言进行比较,并准确报告问题内容和位置。无需插件、配置或自定义测试代码。

CheckSeverityWhat it catches
missing-keyserrorKey exists in reference but is absent in a translation
extra-keyserrorKey exists in translation but not in the reference
placeholderserror{price}, {{name}}, %s differ between languages
plural-structureerrorPlural forms are malformed or missing required categories
missing-languageserrorExpected language has no files or directory
orphaned-languageserrorLanguage files exist but are not in the expected list
parse-errorserrorFile fails to parse (broken JSON, XML, YAML, etc.)
empty-valueswarningKey is present but the translation is an empty string
untranslatedwarningTranslation is identical to the reference language
Terminal output
i18n-validate v0.1.0 — validating ./locales

  Reference: en (2 files: translation.json, apiTester.json)
  Languages: de, ja, fr, es, zh-Hans, pt-BR, ko (7 found, 7 expected)
  Layout   : directory (auto-detected)
  Formats  : i18next JSON (auto-detected)

────────────────────────────────────────────────

ERRORS (5)

  ✗ missing-keys │ translation.json
    Key "settings.billing.title"
      missing in: ja, ko

  ✗ placeholders │ translation.json
    Key "pricing.total" — expected: {price}, {currency}
      de:  found {price} only — missing {currency}

────────────────────────────────────────────────

WARNINGS (2)

  ⚠ empty-values │ translation.json
    Key "onboarding.step3.hint"
      empty in: de, fr

────────────────────────────────────────────────

  5 errors, 2 warnings across 7 languages
  ✗ Validation failed

安装

使用您偏好的软件包管理器将其安装为全局 CLI 工具。npm 包内置原生 Rust 二进制文件,无需编译或运行时依赖。

Terminal
npm install -g @i18n-agent/i18n-validate
npm 包为 macOS、Linux 和 Windows 内置预编译原生二进制文件,无需 Rust 工具链。

用法

将工具指向本地化目录。它会自动检测参考语言、目录布局和文件格式。大多数项目无需任何配置。

Terminal
# Zero-config validation
i18n-validate ./locales

# JSON output for scripting
i18n-validate ./locales --format json | jq '.summary'

# CI/CD with JUnit XML
i18n-validate ./locales --format junit -o i18n-report.xml

CI/CD 集成

将翻译验证添加到拉取请求管线。工具会输出 JUnit XML,可与 GitHub Actions 测试报告器、GitLab CI 产物以及任何支持 JUnit 的 CI 系统集成。

.github/workflows/validate-i18n.yml
name: Validate Translations
on:
  pull_request:
    paths: ['locales/**', 'public/locales/**']

jobs:
  validate:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - name: Validate translations
        run: npx @i18n-agent/i18n-validate ./locales --format junit -o i18n-report.xml

      - uses: dorny/test-reporter@v1
        if: always()
        with:
          name: i18n validation
          path: i18n-report.xml
          reporter: java-junit
The tool exits with code 1 when errors are found, so it naturally fails CI. Use --strict to also fail on warnings.

支持的格式

验证器由 i18n-convert 驱动,开箱即用地支持 32 种 i18n 文件格式。无需特定格式的插件或配置,工具会根据文件扩展名和内容自动检测格式。

Mobile & Desktop

Android XML, Xcode String Catalog, iOS Strings, iOS Stringsdict, Flutter ARB, Qt Linguist

Web & Frameworks

Structured JSON, i18next JSON, JSON5, HJSON, YAML (Rails), YAML (Plain), JavaScript, TypeScript, PHP/Laravel, NEON

Standards & Exchange

XLIFF 1.2, XLIFF 2.0, Gettext PO, TMX, .NET RESX, Java Properties

Data & Other

CSV, Excel (.xlsx), TOML, INI, SRT Subtitles, Markdown, Plain Text

配置

大多数项目使用零配置即可。当您需要控制检查严重程度、设置预期语言或排除开发中的语言时,可在项目根目录创建 .i18n-validate.toml 文件。

.i18n-validate.toml
# .i18n-validate.toml
ref = "en"
expect = ["de", "ja", "fr", "es", "zh-Hans", "pt-BR", "ko"]

[checks]
missing-keys = "error"
extra-keys = "error"
placeholders = "error"
empty-values = "warning"
untranslated = "warning"

[languages.ko]
missing-keys = "warning"    # Korean is WIP

[languages.ar]
skip = true                 # Exclude from validation

立即试用 i18n Agent

将翻译文件拖放到此处

JSON, YAML, PO, XML, CSV, Markdown, Properties

或点击选择文件

目标语言

无需注册即时估价

常见问题