翻译

在 GitHub Actions 中检查翻译

一个翻译如果丢失了 {name} 或跳过了一个键,会在运行时破坏应用程序,而审查很少能发现。此工作流在每次拉取请求时运行 kaeris check 并使作业标为红色。它是离线的且免费的:无需 API 密钥,无需账户。

KAERIS 翻译了此页面,并通过回译检查了每一行。尚未经过母语人士审阅。 英文原文

配置

工作流

将其另存为 .github/workflows/i18n-check.yml。将 source 更改为您的基础语言文件,将 languages 更改为您发布的区域设置。

配置.github/workflows/i18n-check.yml
name: i18n check
on: pull_request
jobs:
  check:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: kaeris-io/kaeris-action@v1
        with:
          mode: check
          source: locales/en.json
          languages: de,fr

不用 Python:npx

npm 包 kaeris 在 Node 18 及以上版本运行同样的检查;npx 会自动下载,无需安装步骤。包里只有 check:翻译需要 Python 包。

配置.github/workflows/i18n-check.yml (steps)
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-node@v4
        with:
          node-version: 20
      - run: npx kaeris check --source locales/en.json --langs de,fr

不带 Action 的相同功能

使用 Python 和 pip 的纯粹步骤。日志会逐行显示每个发现项,而不是 Action 打印的表格。

配置.github/workflows/i18n-check.yml (steps)
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-python@v5
        with:
          python-version: "3.12"
      - run: pip install kaeris
      - run: kaeris check --source locales/en.json --langs de,fr --ci

在合并请求的确切行上发现问题(可选)

Action 还可以生成 SARIF 报告;上传该报告会将每个发现项转换为 diff 中的注释。代码扫描上传在公共仓库上是免费的;私有仓库需要 GitHub Advanced Security。

配置.github/workflows/i18n-check.yml
name: i18n check
on: pull_request
permissions:
  contents: read
  security-events: write
jobs:
  check:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: kaeris-io/kaeris-action@v1
        with:
          mode: check
          source: locales/en.json
          languages: de,fr
          sarif-file: kaeris.sarif
      - uses: github/codeql-action/upload-sarif@v3
        if: always()
        with:
          sarif_file: kaeris.sarif

实际运行时打印的内容

kaeris 0.2.35 的输出,捕获于 27 October 2026。每个框的最后一行是 CI 作业看到的退出代码。

作业打印的内容

Action 为每种语言打印一个摘要表,并在出现问题时以错误行结尾。左侧:正常的文件。右侧:de.json 文件,其中包含 {nam} 而不是 {name},并且 checkout 键丢失。

正常的文件Action step output
## KAERIS i18n — CI check

Placeholder-loss: **0** (should be 0).

| Language | Status | Missing | Placeholder issues | Translated |
|---|---|---|---|---|
| de | ✓ complete | 0 | 0 | – |
| fr | ✓ complete | 0 | 0 | – |

_Generated from `kaeris check --json` — no fabricated numbers._
step exit=0
--- GITHUB_OUTPUT (without summary body):
missing=0
placeholder-issues=0
changed=false
check-exit-code=0
translate-exit-code=0
损坏的翻译Action step output
## KAERIS i18n — CI check

Placeholder-loss: **1** (should be 0).
Missing keys remaining: **1**.

| Language | Status | Missing | Placeholder issues | Translated |
|---|---|---|---|---|
| de | ⚠ 1 missing, 1 placeholder issue | 1 | 1 | – |
| fr | ✓ complete | 0 | 0 | – |

_Generated from `kaeris check --json` — no fabricated numbers._
::error::kaeris check found incomplete/broken translations — see the job summary for the language matrix
step exit=1
--- GITHUB_OUTPUT (without summary body):
missing=1
placeholder-issues=1
changed=false
check-exit-code=1
translate-exit-code=0

npx 步骤的输出

同一个项目用 npx 检查:来自 npm 的 kaeris 0.2.37,空的 npm 缓存,CI=true,与全新 runner 相同。第一行是 npm 在安装这个包。

正常的文件npx step output
$ npx kaeris check --source locales/en.json --langs de,fr
npm warn exec The following package was not found and will be installed: [email protected]
✓ de: complete & placeholder-safe
✓ fr: complete & placeholder-safe
✓ all locales complete & placeholder-safe
exit code: 0
损坏的翻译npx step output
$ npx kaeris check --source locales/en.json --langs de,fr
npm warn exec The following package was not found and will be installed: [email protected]
✗ de: 1 missing key(s): checkout
✗ de: 1 placeholder mismatch(es):
    greeting: missing ['{name}'], added ['{nam}']
✗ de: 2 translation fault(s):
    greeting: lost placeholder {name}
    greeting: invented placeholder {nam} (not in source)
✓ fr: complete & placeholder-safe
✗ 1 missing key, 1 placeholder mismatch, 2 translation faults
exit code: 1

分三步设置

  1. 保存工作流

    创建 .github/workflows/i18n-check.yml 文件,其中包含上述工作流,并配置你自己的 source 和 languages。

  2. 打开一个合并请求

    推送一个更改了区域设置文件的分支。该作业会在每个合并请求上运行,并在丢失占位符或缺少键时显示红色。

  3. 将检查设为必需

    在仓库设置中,将该作业添加为分支保护中的必需状态检查。红色的作业将阻止合并。

我们是如何检查的

页面上的每个命令在编写之前都已运行。未运行的命令也列出了。

值得了解的选项

问题

是否需要 API 密钥或账户?

否。kaeris check 在其帮助文档中被描述为静态、本地且无 API 的,因此该作业不需要密钥。翻译是一个单独的命令,需要密钥。

它支持哪些文件格式?

kaeris check 的帮助文档列出了 JSON、ARB、YAML、.strings、.xcstrings、.po、Android XML、CSV、XLIFF、.properties、.resx、Fluent 和 Markdown 作为源格式(kaeris 0.2.35 及更高版本)。按格式的指南

什么会导致作业失败?

kaeris check 的退出代码:0 表示干净,1 表示发现问题,2 表示用法错误或无法读取的文件。检查标记为红色的问题会导致作业失败;strict 模式还会导致陈旧的键失败。GitHub Action 参考

继续

其他配置示例:GitLab CI · pre-commit · Make 和 npm 脚本

CLI 参考 · 检查参考 · GitHub Action 参考 · 浏览器中的免费检查 · 浏览器中的翻译