Translate Apple Localizable.xcstrings files using Claude AI
Project description
XCStrings Translator
Translate Apple's Localizable.xcstrings files using AI. Supports Claude, GPT, and Gemini.
xcstrings translate Localizable.xcstrings -l fr,es,it,ja,ko
Features
- Multi-provider - Choose Claude, GPT, or Gemini based on cost/quality needs
- Context-aware - Uses existing translations to understand meaning and tone
- Format-safe - Preserves
%@,%lld,%1$@and other specifiers - 35+ languages - All major App Store locales
- Recursive - Point at a directory to translate every nested
.xcstringsfile - Cost estimation - Preview costs before translating
- Validation - Detect missing translations and format mismatches
Quick Start
# Install
pip install xcstrings-translator
# Set API key (pick one)
export ANTHROPIC_API_KEY=sk-... # Claude
export OPENAI_API_KEY=sk-... # GPT
export GOOGLE_API_KEY=... # Gemini
export OPENROUTER_API_KEY=sk-or-... # OpenRouter (any vendor)
# Translate
xcstrings translate Localizable.xcstrings -l fr,de,ja
Models
| Model | Provider | Cost/1M tokens | Best for |
|---|---|---|---|
haiku |
Anthropic | $1 in / $5 out | Fast iteration |
sonnet |
Anthropic | $3 in / $15 out | Recommended (default) |
opus |
Anthropic | $5 in / $25 out | Highest quality |
gpt-5.4-nano |
OpenAI | $0.20 in / $1.25 out | Cheapest |
gpt-5.4 |
OpenAI | $2.50 in / $15 out | Quality |
gpt-5.5 |
OpenAI | $5 in / $30 out | Flagship |
gemini-3.5-flash |
$1.50 in / $9 out | Fast & balanced | |
gemini-3.1-pro |
$2 in / $12 out | Quality |
Older aliases still work:
gpt-5,gpt-5-mini,gpt-5-nano,o3,o4-mini,gemini-2.5-pro/flash,gemini-2.0-flash.
xcstrings translate input.xcstrings -l fr -m haiku # fast/cheap
xcstrings translate input.xcstrings -l fr -m sonnet # balanced (default)
xcstrings translate input.xcstrings -l fr -m gpt-5.4-nano # cheapest
OpenRouter
Route through OpenRouter to reach any vendor with one key. Set
OPENROUTER_API_KEY, then pass an openrouter:vendor/model string or a shorthand alias:
| Alias | Model |
|---|---|
or-opus, or-sonnet, or-haiku |
Anthropic Claude (Opus 4.8 / Sonnet 4.6 / Haiku 4.5) |
or-gpt-5.5, or-gpt-5.4, or-gpt-5.4-mini, or-gpt-5.4-nano |
OpenAI GPT-5.5 / 5.4 family |
or-gpt-5, or-gpt-5-mini, or-gpt-5-nano |
OpenAI GPT-5 family |
or-gemini-3.5-flash, or-gemini-3.1-pro, or-gemini-3-flash |
Google Gemini 3.x |
or-gemini-pro, or-gemini-flash |
Google Gemini 2.5 Pro / Flash |
xcstrings translate input.xcstrings -l fr -m openrouter:anthropic/claude-sonnet-4.6
xcstrings translate input.xcstrings -l fr -m or-gpt-5.4-nano
Cost estimates for openrouter:* models are fetched live from OpenRouter's public
model catalog (cached ~24h under ~/.cache/xcstrings-translator/), so any model — even
brand-new ones — gets accurate pricing in estimate/--dry-run. Pass --no-fetch to
skip the network and use cached/static prices only.
Commands
| Command | Description |
|---|---|
translate |
Translate to specified languages |
estimate |
Preview cost without translating |
info |
Show file stats and coverage |
validate |
Check for issues |
languages |
List all 35+ supported languages |
Usage Examples
# Translate to multiple languages
xcstrings translate Localizable.xcstrings -l fr,es,it,de,ja
# Translate every .xcstrings under a project directory (recursive; asks first)
xcstrings translate ./MyApp -l fr,es,it
xcstrings translate ./MyApp --fill-missing -y # skip the confirmation prompt
# Estimate cost first
xcstrings translate Localizable.xcstrings -l fr,es,it --dry-run
# Use faster model
xcstrings translate Localizable.xcstrings -l fr -m haiku
# Parallel requests (faster for large files)
xcstrings translate Localizable.xcstrings -l fr,es -c 32
# Save to different file
xcstrings translate input.xcstrings -l fr -o translated.xcstrings
# Fill missing translations only
xcstrings translate Localizable.xcstrings --fill-missing
# Check translation coverage
xcstrings info Localizable.xcstrings
# Validate format specifiers
xcstrings validate Localizable.xcstrings
App Context
Provide context for better translations. Create context.md next to your xcstrings file:
# My Fitness App
A workout tracking app for athletes.
Tone: Motivational, energetic.
Use informal "you" (du/tu).
Or pass directly:
xcstrings translate input.xcstrings -l fr --context "A fitness app with motivational tone"
Python API
from xcstrings_translator import XCStringsFile, XCStringsTranslator
# Load
xcstrings = XCStringsFile.from_file("Localizable.xcstrings")
# Translate
translator = XCStringsTranslator(model="sonnet")
xcstrings = translator.translate_file(xcstrings, ["fr", "es", "it"])
# Save
xcstrings.to_file("Localizable.xcstrings")
# Stats
print(f"Translated: {translator.stats.translated}")
print(f"Cost: ${translator.stats.input_tokens * 3 / 1e6 + translator.stats.output_tokens * 15 / 1e6:.2f}")
Supported Languages
European: en, de, fr, es, it, pt, pt-BR, pt-PT, nl, pl, sv, da, nb, fi, cs, sk, hu, ro, bg, el, sq, uk, ru, tr
Asian: ja, ko, zh-Hans, zh-Hant, th, vi, id, ms, hi
Middle Eastern: ar, he
Other: ca, eu
Options
| Option | Description | Default |
|---|---|---|
-l, --languages |
Target language codes | Required |
-m, --model |
AI model | sonnet |
-o, --output |
Output file | Overwrites input |
-b, --batch-size |
Strings per API call | 25 |
-c, --concurrency |
Parallel requests | 32 |
--context |
App description | context.md |
--overwrite |
Replace existing | false |
--dry-run |
Estimate only | false |
-f, --fill-missing |
Auto-detect languages | false |
-y, --yes |
Skip confirmation for directory runs | false |
Troubleshooting
"Unsupported language" - Use Apple codes: zh-Hans not zh-CN, pt-BR not pt_BR
Format mismatch - Run xcstrings validate to find issues
API errors - Check correct key is set for your model
Contributing
Contributions are welcome! See CONTRIBUTING.md for dev setup, tests, and the release process. Please also review our Code of Conduct. To report a security issue, see SECURITY.md.
License
MIT
Made with ❤️ by Justin Lanfermann
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file xcstrings_translator-1.1.1.tar.gz.
File metadata
- Download URL: xcstrings_translator-1.1.1.tar.gz
- Upload date:
- Size: 38.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6f74d88e29478ee48a0e7e860871803624a210807e2f7ca96af5977e958490fe
|
|
| MD5 |
b481de4695f76f1b6c043a0576392fb0
|
|
| BLAKE2b-256 |
1b86ea91b12b83cdf8a9784dc0559f548cc5546345631dad4de1d0ae381f0531
|
Provenance
The following attestation bundles were made for xcstrings_translator-1.1.1.tar.gz:
Publisher:
publish.yml on jaylann/XCStringsTranslator
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
xcstrings_translator-1.1.1.tar.gz -
Subject digest:
6f74d88e29478ee48a0e7e860871803624a210807e2f7ca96af5977e958490fe - Sigstore transparency entry: 1746401032
- Sigstore integration time:
-
Permalink:
jaylann/XCStringsTranslator@68793a0d0c2d2a3931ecec52118f95e27d37896b -
Branch / Tag:
refs/tags/v1.1.1 - Owner: https://github.com/jaylann
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@68793a0d0c2d2a3931ecec52118f95e27d37896b -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file xcstrings_translator-1.1.1-py3-none-any.whl.
File metadata
- Download URL: xcstrings_translator-1.1.1-py3-none-any.whl
- Upload date:
- Size: 24.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8f8811170f6485f75f67716768aa70e58daf6cfd98ec3cac53dcb05b8067bc2b
|
|
| MD5 |
085e0bc5650e7f42b788cf2b2c3ed0e7
|
|
| BLAKE2b-256 |
af1d40c9e0f7baab25c92f00125cd52dad2423354d1e0817b1b6b0e3e8d88351
|
Provenance
The following attestation bundles were made for xcstrings_translator-1.1.1-py3-none-any.whl:
Publisher:
publish.yml on jaylann/XCStringsTranslator
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
xcstrings_translator-1.1.1-py3-none-any.whl -
Subject digest:
8f8811170f6485f75f67716768aa70e58daf6cfd98ec3cac53dcb05b8067bc2b - Sigstore transparency entry: 1746401226
- Sigstore integration time:
-
Permalink:
jaylann/XCStringsTranslator@68793a0d0c2d2a3931ecec52118f95e27d37896b -
Branch / Tag:
refs/tags/v1.1.1 - Owner: https://github.com/jaylann
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@68793a0d0c2d2a3931ecec52118f95e27d37896b -
Trigger Event:
workflow_dispatch
-
Statement type: