Skip to content

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.

Input (locales/en.json):

{
"greeting": "Hello!",
"farewell": "Goodbye!",
"login": "Log in",
"signup": "Sign up",
"settings": "Settings"
}
Terminal window
yaku --to zh-TW -f locales/en.json -o locales/zh-TW.json
yaku --to ja -f locales/en.json -o locales/ja.json

Output (locales/zh-TW.json):

{
"greeting": "你好!",
"farewell": "再見!",
"login": "登入",
"signup": "註冊",
"settings": "設定"
}

yaku handles deeply nested JSON:

{
"nav": {
"home": "Home",
"about": "About Us"
},
"errors": {
"404": "Page not found",
"500": "Internal server error"
}
}
Terminal window
yaku --to zh-TW -f en.json -o zh-TW.json

All keys, nesting, numbers, and booleans are preserved. Only string values are translated.

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"
Terminal window
yaku --to ja -f config/locales/en.yaml -o config/locales/ja.yaml

Output (config/locales/ja.yaml):

en:
activerecord:
errors:
messages:
blank: "空白にはできません"
invalid: "は無効です"
taken: "はすでに使用されています"
views:
pagination:
next: "次へ"
previous: "前へ"
first: "最初"
last: "最後"

Translate one source file into multiple languages:

#!/bin/bash
SOURCE="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"
done

UI terms often need precise, consistent translations. Create a glossary:

.yaku-glossary.yaml
zh-TW:
Sign up: 註冊
Log in: 登入
Log out: 登出
Settings: 設定
Dashboard: 儀表板
Profile: 個人資料
ja:
Sign up: サインアップ
Log in: ログイン
Log out: ログアウト
Settings: 設定
Dashboard: ダッシュボード
Terminal window
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.