Recipe: Translate i18n Files
This recipe shows how to translate localization files for web and mobile apps. yaku extracts string values, translates them, and writes them back — keys and structure are never touched by the LLM.
JSON i18n files
Section titled “JSON i18n files”Flat structure
Section titled “Flat structure”Input (locales/en.json):
{ "greeting": "Hello!", "farewell": "Goodbye!", "login": "Log in", "signup": "Sign up", "settings": "Settings"}yaku --to zh-TW -f locales/en.json -o locales/zh-TW.jsonyaku --to ja -f locales/en.json -o locales/ja.jsonOutput (locales/zh-TW.json):
{ "greeting": "你好!", "farewell": "再見!", "login": "登入", "signup": "註冊", "settings": "設定"}Nested structure
Section titled “Nested structure”yaku handles deeply nested JSON:
{ "nav": { "home": "Home", "about": "About Us" }, "errors": { "404": "Page not found", "500": "Internal server error" }}yaku --to zh-TW -f en.json -o zh-TW.jsonAll keys, nesting, numbers, and booleans are preserved. Only string values are translated.
YAML i18n files
Section titled “YAML i18n files”Rails-style i18n
Section titled “Rails-style i18n”Input (config/locales/en.yaml):
en: activerecord: errors: messages: blank: "can't be blank" invalid: "is invalid" taken: "has already been taken" views: pagination: next: "Next" previous: "Previous" first: "First" last: "Last"yaku --to ja -f config/locales/en.yaml -o config/locales/ja.yamlOutput (config/locales/ja.yaml):
en: activerecord: errors: messages: blank: "空白にはできません" invalid: "は無効です" taken: "はすでに使用されています" views: pagination: next: "次へ" previous: "前へ" first: "最初" last: "最後"Batch translation
Section titled “Batch translation”Translate one source file into multiple languages:
#!/bin/bashSOURCE="locales/en.json"LANGUAGES=("zh-TW" "ja" "ko" "fr" "de" "es")
for lang in "${LANGUAGES[@]}"; do yaku --to "$lang" -f "$SOURCE" -o "locales/${lang}.json" echo "Generated locales/${lang}.json"doneUsing a glossary for UI terms
Section titled “Using a glossary for UI terms”UI terms often need precise, consistent translations. Create a glossary:
zh-TW: Sign up: 註冊 Log in: 登入 Log out: 登出 Settings: 設定 Dashboard: 儀表板 Profile: 個人資料
ja: Sign up: サインアップ Log in: ログイン Log out: ログアウト Settings: 設定 Dashboard: ダッシュボードyaku --to zh-TW -f locales/en.json -o locales/zh-TW.json# Glossary loaded automatically from .yaku-glossary.yaml- Translate from the source locale. Always translate from
en.json(or your source language), not from another translated file. - Use a glossary for UI consistency. Buttons, labels, and navigation items should use the same terms everywhere.
- Review pluralization. Some languages handle plurals differently. Check that plural forms are handled correctly in your i18n framework after translation.
- Watch for interpolation variables. If your i18n files contain variables like
{{name}}or%{count}, verify they are preserved in the output.