# Example: Basic Translation This example demonstrates the most common use case: translating a JSON i18n file to multiple languages. ## Scenario User has `locales/en.json` containing English translations and wants to add Chinese, Japanese, and Korean support. ## User Request > "Translate my en.json to Chinese, Japanese, and Korean" ## Claude's Workflow ### Step 1: Understand the Request Claude recognizes: - **Task**: Translation - **Source file**: en.json (implied to be in locales/) - **Target languages**: Chinese (zh), Japanese (ja), Korean (ko) - **Mode**: First-time translation (full, not incremental) ### Step 2: Locate the Source File ```bash # Find JSON files in locale directories find . -type f -name "en.json" \( -path "*/locales/*" -o -path "*/locale/*" -o -path "*/i18n/*" \) ``` Output: ``` ./locales/en.json ``` ### Step 3: Check Environment ```bash # Verify jta is installed jta --version ``` If not installed: ```bash # Install via Homebrew (macOS) brew tap hikanner/jta && brew install jta ``` Check API key: ```bash # Check if API key exists if [[ -n "$OPENAI_API_KEY" ]]; then echo "โœ“ API key found" fi ``` ### Step 4: Preview Source File ```bash # Show file structure jq '.' locales/en.json | head -20 ``` Output: ```json { "app": { "name": "My App", "welcome": "Welcome to {appName}!" }, "settings": { "title": "Settings", "language": "Language" } } ``` ### Step 5: Execute Translation ```bash # Translate to Chinese, Japanese, and Korean jta locales/en.json --to zh,ja,ko -y ``` **What happens:** 1. **Terminology Detection**: Jta analyzes content and detects important terms 2. **Batch Processing**: Splits into batches (default 20 keys per batch) 3. **Translation**: Sends each batch to AI provider 4. **Agentic Reflection**: AI evaluates and improves translations 5. **Output**: Creates zh.json, ja.json, ko.json ### Step 6: Monitor Progress Console output: ``` ๐Ÿ“„ Loading source file... โœ“ Source file loaded (100 keys) ๐Ÿ“š Loading terminology... ๐Ÿ” Detecting terminology... โœ“ Detected 8 terms (3 preserve, 5 consistent) ๐Ÿค– Translating to Chinese (zh)... Processing โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ” 100% (100/100) โœ“ Chinese translation completed ๐Ÿค– Translating to Japanese (ja)... Processing โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ” 100% (100/100) โœ“ Japanese translation completed ๐Ÿค– Translating to Korean (ko)... Processing โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ” 100% (100/100) โœ“ Korean translation completed ๐Ÿ’พ Saving translations... โœ“ Saved to locales/zh.json โœ“ Saved to locales/ja.json โœ“ Saved to locales/ko.json ``` ### Step 7: Verify Results ```bash # Check created files ls -lh locales/*.json ``` Output: ``` -rw-r--r-- 1 user staff 2.3K en.json -rw-r--r-- 1 user staff 2.8K zh.json -rw-r--r-- 1 user staff 3.1K ja.json -rw-r--r-- 1 user staff 2.9K ko.json ``` Validate JSON structure: ```bash for file in locales/{zh,ja,ko}.json; do if jq empty "$file" 2>/dev/null; then echo "โœ“ $file is valid JSON" fi done ``` ### Step 8: Show Statistics ``` ๐Ÿ“Š Translation Statistics Chinese (zh): Total items: 100 Success: 100 Failed: 0 Duration: 45s API calls: 15 (5 translate + 5 reflect + 5 improve) Japanese (ja): Total items: 100 Success: 100 Failed: 0 Duration: 48s API calls: 15 Korean (ko): Total items: 100 Success: 100 Failed: 0 Duration: 43s API calls: 15 Total Duration: 2m 16s Total API calls: 45 Estimated cost: ~$0.90 (using GPT-4o) Terminology saved to .jta/ directory for future consistency. ``` ## Claude's Response to User ``` โœ… Translation completed successfully! I've translated your en.json to Chinese, Japanese, and Korean. **Files created:** - `locales/zh.json` (Chinese Simplified) - `locales/ja.json` (Japanese) - `locales/ko.json` (Korean) **Statistics:** - Total items: 100 per language - Success rate: 100% - Duration: 2 minutes 16 seconds - API calls: 45 total (15 per language with Agentic reflection) - Estimated cost: ~$0.90 **Terminology management:** Jta detected 8 important terms and saved them to `.jta/` directory: - Preserve terms (never translate): API, OAuth, JSON - Consistent terms (translate uniformly): credits, workspace, settings, profile, template All placeholders ({appName}), HTML tags, and URLs have been preserved in the translations. Would you like me to show you a sample of the translations or make any adjustments? ``` ## Sample Translations ### English (source) ```json { "app": { "welcome": "Welcome to {appName}!", "description": "Manage your workspace settings" }, "user": { "credits": "You have {count} credits remaining" } } ``` ### Chinese (zh.json) ```json { "app": { "welcome": "ๆฌข่ฟŽๆฅๅˆฐ {appName}!", "description": "็ฎก็†ๆ‚จ็š„ๅทฅไฝœ็ฉบ้—ด่ฎพ็ฝฎ" }, "user": { "credits": "ๆ‚จ่ฟ˜ๆœ‰ {count} ็งฏๅˆ†" } } ``` ### Japanese (ja.json) ```json { "app": { "welcome": "{appName}ใธใ‚ˆใ†ใ“ใ!", "description": "ใƒฏใƒผใ‚ฏใ‚นใƒšใƒผใ‚นใฎ่จญๅฎšใ‚’็ฎก็†" }, "user": { "credits": "ๆฎ‹ใ‚Š {count} ใ‚ฏใƒฌใ‚ธใƒƒใƒˆใŒใ‚ใ‚Šใพใ™" } } ``` ### Korean (ko.json) ```json { "app": { "welcome": "{appName}์— ์˜ค์‹  ๊ฒƒ์„ ํ™˜์˜ํ•ฉ๋‹ˆ๋‹ค!", "description": "์›Œํฌ์ŠคํŽ˜์ด์Šค ์„ค์ • ๊ด€๋ฆฌ" }, "user": { "credits": "{count}๊ฐœ์˜ ํฌ๋ ˆ๋”ง์ด ๋‚จ์•„ ์žˆ์Šต๋‹ˆ๋‹ค" } } ``` ## Notes - All placeholders (`{appName}`, `{count}`) preserved - HTML tags (``) preserved - Terminology consistency maintained ("workspace" โ†’ "ๅทฅไฝœ็ฉบ้—ด", "ใƒฏใƒผใ‚ฏใ‚นใƒšใƒผใ‚น", "์›Œํฌ์ŠคํŽ˜์ด์Šค") - Agentic reflection ensured natural, fluent translations