翻译 Flutter ARB 文件并检查结果
app_de.arb 落后于 app_en.arb:少了一个键,丢了一个 ICU 分支。对缺少的键,gen-l10n 会使用模板中的文本,于是缺口被发布出去。下面一条命令找出它,另一条补上。
KAERIS 翻译了此页面,并通过回译检查了每一行。尚未经过母语人士审阅。 英文原文
示例项目
一个小型 Flutter ARB 项目:英文源文件和一个落后的德语文件。下面的命令就是在这些文件上运行的。
{
"@@locale": "en",
"greeting": "Hi, {name}!",
"@greeting": {
"placeholders": { "name": { "type": "String" } }
},
"unreadCount": "{count, plural, =0{No new messages} =1{1 new message} other{{count} new messages}}",
"@unreadCount": {
"placeholders": { "count": { "type": "int" } }
},
"signOut": "Sign out",
"lastSeen": "Last seen {date}",
"@lastSeen": {
"placeholders": { "date": { "type": "DateTime", "format": "yMMMd" } }
}
}
{
"@@locale": "de",
"greeting": "Hallo, {name}!",
"unreadCount": "{count, plural, =0{Keine neuen Nachrichten} other{Neue Nachrichten}}",
"signOut": "Abmelden"
}
1. 找出缺少的内容
kaeris check 把每个译文与源文件逐一比较。它离线运行,不需要密钥或账号,发现问题时以退出码 1 结束,CI 任务可以就此停下。
$ npx kaeris check --source lib/l10n/app_en.arb --langs de
✗ de: 1 missing key(s): lastSeen
✗ de: 2 translation fault(s):
unreadCount: number 1 from the source is missing or changed in the translation
unreadCount: ICU exact-match branch =1 {…} was dropped in the translation
✗ 1 missing key, 2 translation faults
2. 只翻译缺少的键
--only-new 只发送德语文件缺少的键,并把它们写入文件。文件里已有的行保持原样,坏掉的行也一样。该命令在 Python 包中:pip install kaeris。
$ kaeris translate lib/l10n/app_en.arb --langs de --only-new
→ no key: free demo limits 10,000 chars per file, 8 languages per run, get a key: kaeris.dev/developer
→ de: 1 new key(s) to translate
→ Run: openai/gpt-6-luna · Free · 1/1 languages · 1 strings · 3.5s
16 charged
✓ Translation QA: no placeholder loss, no overflow risks
→ Project memory: +1 · 1 strings, 1 translations in kaeris-tm.json
✓ de: merged 1 key(s) → lib/l10n/app_de.arb
→ 3 key(s) already exist in de but nothing in kaeris.lock vouches for them, so they were left alone AND left unlocked. If the source changed after those files were made, those edits are NOT translated. Re-run once with --no-only-new to rebuild them, or with --assume-current if the files are known to match.
{
"@@locale": "de",
"greeting": "Hallo, {name}!",
"unreadCount": "{count, plural, =0{Keine neuen Nachrichten} other{Neue Nachrichten}}",
"signOut": "Abmelden",
"lastSeen": "Zuletzt gesehen {date}"
}
3. 再检查一次
缺少的键已补上。剩下的是这次运行之前就已坏掉的行:手动修正,或用 --no-only-new 重新翻译整个文件。
$ npx kaeris check --source lib/l10n/app_en.arb --langs de
✗ de: 2 translation fault(s):
unreadCount: number 1 from the source is missing or changed in the translation
unreadCount: ICU exact-match branch =1 {…} was dropped in the translation
✗ 2 translation faults
2026 年 11 月 2 日在免费方案下运行,未使用密钥:检查用 npx kaeris 0.2.42,翻译用 PyPI 上的 kaeris 0.2.42。输出按原样展示,只省略了进度行和本地文件夹路径。
kaeris check 在 Flutter ARB 中能发现什么
缺少的键
app_en.arb中有而app_de.arb中没有的键。译文不需要@key元数据。ICU 精确分支
丢失的
=1分支会被报告,其中的数字也会被报告。改名的占位符
用
{userName}代替{name}会被报告为丢失一个、新造一个。缺少
other缺少
other分支的 plural 或 select 视为错误。
费用
kaeris check免费在你的机器上运行:无需密钥,无需账号,没有限额。
翻译可以免费开始
不用密钥:每个文件 10,000 字符,每天 300,000 字符,每次运行最多 8 种语言。免费密钥可提高到每个文件 50,000 字符、每月 1.5M 字符。用量按每种目标语言各计一次字符数。
超出免费方案时
Lifetime 一次性 $79,使用你自己的 OpenRouter 密钥,模型费用另付。Pro 每月 $19 或每年 $190,每月 12M 字符。价格
问题
app_de.arb 需要 @metadata 条目吗?
不需要。占位符只在 app_en.arb 中描述一次。检查不要求译文中有 @key 条目,上面的运行也没有添加。
能配合 gen-l10n 使用吗?
能。文件保持 flutter gen-l10n 从 lib/l10n 读取的 app_<lang>.arb 名称。另见 ARB 文件。
可以在 CI 中运行吗?
可以。npx kaeris check 发现问题时以退出码 1 结束。示例:GitHub Actions、GitLab CI、pre-commit。
继续
check 参考 · CLI 参考 · 在浏览器中免费检查 · 在浏览器中翻译
其他技术栈: react-i18next · next-intl · vue-i18n · iOS · Android