# Example: Incremental Translation This example demonstrates how to update existing translations when you add new content to your source file. ## Scenario User has already translated `en.json` to Chinese (`zh.json`). Now they've added 5 new keys and modified 2 existing keys in `en.json`. They want to update `zh.json` without re-translating everything. ## User Request > "I added new keys to my en.json, please update the Chinese translation" ## Claude's Workflow ### Step 1: Understand the Context Claude recognizes: - **Task**: Update existing translation - **Source file**: en.json - **Target**: Chinese (zh.json already exists) - **Mode**: Incremental (only translate changes) ### Step 2: Check Existing Translation ```bash # Verify both files exist ls -lh locales/en.json locales/zh.json ``` Output: ``` -rw-r--r-- 1 user staff 2.8K en.json (modified 5 minutes ago) -rw-r--r-- 1 user staff 2.6K zh.json (created 2 days ago) ``` ### Step 3: Execute Incremental Translation ```bash # Use incremental mode jta locales/en.json --to zh --incremental ``` ### Step 4: Analyze Changes Console output: ``` ๐Ÿ“„ Loading source file... โœ“ Source file loaded (105 keys) ๐Ÿ“„ Loading existing translation... โœ“ Existing translation loaded (98 keys) ๐Ÿ” Analyzing changes... Changes detected: ๐Ÿ“ New keys: 5 โœ๏ธ Modified keys: 2 โœ… Unchanged keys: 93 ๐Ÿ—‘๏ธ Deleted keys: 1 Breakdown: New keys: - settings.notification.email - settings.notification.push - user.preferences.theme - user.preferences.language - app.features.newFeature Modified keys: - app.welcome (content changed) - user.credits (content changed) Deleted keys: - app.deprecated (will be removed from translation) Continue with incremental translation? [Y/n] ``` ### Step 5: User Confirms Since the request included "update", Claude proceeds: ```bash # Continue (non-interactive with -y would skip prompt) # User presses Y or Claude proceeds automatically ``` ### Step 6: Translate Only Changes Console output: ``` ๐Ÿ“š Loading terminology... โœ“ Terminology loaded (8 terms from .jta/) ๐Ÿค– Translating 7 items (5 new + 2 modified)... Processing โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ” 100% (7/7) โœ“ Translation completed ๐Ÿ”„ Merging with existing translations... โœ“ Merged 93 unchanged translations โœ“ Added 5 new translations โœ“ Updated 2 modified translations โœ“ Removed 1 deleted key ๐Ÿ’พ Saving translation... โœ“ Saved to locales/zh.json ``` ### Step 7: Show Statistics ``` ๐Ÿ“Š Incremental Translation Statistics Target: Chinese (zh) Total source keys: 105 New keys translated: 5 Modified keys: 2 Unchanged keys: 93 (preserved from previous translation) Deleted keys: 1 (removed) Translation performance: Items translated: 7 (5 + 2) Success: 7 Failed: 0 Duration: 8s API calls: 2 (1 translate + 1 reflect) Cost savings: Without incremental: ~$0.30 (105 keys, 15 API calls) With incremental: ~$0.03 (7 keys, 2 API calls) Saved: ~90% ($0.27) ``` ## Claude's Response to User ``` โœ… Chinese translation updated successfully! I've updated your zh.json with the changes from en.json using incremental mode. **Changes applied:** - โœจ Added 5 new translations - โœ๏ธ Updated 2 modified translations - ๐Ÿ—‘๏ธ Removed 1 obsolete translation - โœ… Preserved 93 unchanged translations **New translations added:** 1. `settings.notification.email` โ†’ "็”ตๅญ้‚ฎไปถ้€š็Ÿฅ" 2. `settings.notification.push` โ†’ "ๆŽจ้€้€š็Ÿฅ" 3. `user.preferences.theme` โ†’ "ไธป้ข˜ๅๅฅฝ" 4. `user.preferences.language` โ†’ "่ฏญ่จ€ๅๅฅฝ" 5. `app.features.newFeature` โ†’ "ๆ–ฐๅŠŸ่ƒฝ" **Updated translations:** 1. `app.welcome` โ†’ "ๆฌข่ฟŽๆฅๅˆฐ {appName}๏ผๅผ€ๅง‹ๆ‚จ็š„ๆ—…็จ‹" 2. `user.credits` โ†’ "ๆ‚จ็š„่ดฆๆˆทๆœ‰ {count} ็งฏๅˆ†" **Performance:** - Duration: 8 seconds (vs ~45s for full re-translation) - API calls: 2 (vs 15 for full re-translation) - Cost: ~$0.03 (vs ~$0.30, saved 90%) Your existing high-quality translations were preserved, and only the new/changed content was translated with Agentic reflection for quality assurance. Would you like to update other languages as well? ``` ## Comparison: Incremental vs Full Translation ### Full Translation (without --incremental) ```bash jta en.json --to zh ``` - Translates all 105 keys - Takes ~45 seconds - 15 API calls - Cost: ~$0.30 - May lose existing manual refinements ### Incremental Translation (with --incremental) ```bash jta en.json --to zh --incremental ``` - Translates only 7 changed keys - Takes ~8 seconds - 2 API calls - Cost: ~$0.03 - Preserves existing translations exactly ## How Incremental Detection Works Jta uses content hashing to detect changes: ``` 1. Load source (en.json) 2. Load existing translation (zh.json) 3. For each key in source: - Calculate content hash of source value - Compare with hash stored in previous translation - If different โ†’ mark as "modified" - If not in previous โ†’ mark as "new" 4. For each key in previous translation: - If not in source โ†’ mark as "deleted" 5. Translate only "new" + "modified" 6. Merge with "unchanged" 7. Remove "deleted" ``` ## Sample Changes ### Before (en.json - 2 days ago) ```json { "app": { "welcome": "Welcome to {appName}!", "deprecated": "Old feature (no longer used)" }, "user": { "credits": "You have {count} credits" } } ``` ### After (en.json - now) ```json { "app": { "welcome": "Welcome to {appName}! Start your journey", "features": { "newFeature": "New Feature" } }, "user": { "credits": "Your account has {count} credits", "preferences": { "theme": "Theme", "language": "Language" } }, "settings": { "notification": { "email": "Email notifications", "push": "Push notifications" } } } ``` ### Changes Detected - โœจ **New**: `app.features.newFeature`, `user.preferences.theme`, `user.preferences.language`, `settings.notification.email`, `settings.notification.push` - โœ๏ธ **Modified**: `app.welcome`, `user.credits` - ๐Ÿ—‘๏ธ **Deleted**: `app.deprecated` ### Updated Translation (zh.json) ```json { "app": { "welcome": "ๆฌข่ฟŽๆฅๅˆฐ {appName}๏ผๅผ€ๅง‹ๆ‚จ็š„ๆ—…็จ‹", "features": { "newFeature": "ๆ–ฐๅŠŸ่ƒฝ" } }, "user": { "credits": "ๆ‚จ็š„่ดฆๆˆทๆœ‰ {count} ็งฏๅˆ†", "preferences": { "theme": "ไธป้ข˜ๅๅฅฝ", "language": "่ฏญ่จ€ๅๅฅฝ" } }, "settings": { "notification": { "email": "็”ตๅญ้‚ฎไปถ้€š็Ÿฅ", "push": "ๆŽจ้€้€š็Ÿฅ" } } } ``` ## Best Practices 1. **Always use incremental mode for updates** ```bash jta en.json --to zh --incremental ``` 2. **Full re-translation when needed** - After major terminology changes - When quality is unsatisfactory - When starting fresh ```bash jta en.json --to zh # without --incremental ``` 3. **CI/CD integration** ```bash # In your CI pipeline jta locales/en.json --to zh,ja,ko --incremental -y ``` 4. **Multiple languages** ```bash # Update all languages incrementally jta en.json --to zh,ja,ko,es,fr --incremental -y ```