Zero-dependency Android strings.xml translation and verification using LLMs (Gemini, OpenAI, Anthropic, Ollama).
Project description
android-llm-localization
Translate your Android strings.xml into multiple languages using AI — Gemini, OpenAI, Anthropic, or a local model via Ollama. No paid service, no CSV exports, no copy-paste.
The problem
Localizing an Android app the usual way means exporting strings, running them through Google Translate or some dashboard, cleaning up the output, and re-importing — for every language, every update. It's slow, error-prone, and the translations often feel robotic.
This tool does it differently. It reads your strings.xml, sends it to an LLM with context about your app, and writes the translated files directly into your project. The model understands UI language, keeps format specifiers intact, and produces natural-sounding output rather than word-for-word translations.
Installation
pip install android-localisation
Requires Python 3.8+. No other dependencies.
Quick start
# Step 1 — translate
android-localise translate --api-key YOUR_GEMINI_KEY
# Step 2 — fix any formatting issues the LLM may have introduced
android-localise fix
# Step 3 — verify nothing will crash at runtime
android-localise verify
That's the full workflow. Run these three commands after every time you update your English strings.
What happens when you run translate
When you run android-localise translate --api-key YOUR_KEY, here's exactly what it does:
- Looks for
app/src/main/res/values/strings.xml— this is your English source - If
--languagesis provided, creates any missingvalues-<lang>/folders automatically. Otherwise scans theres/directory for existingvalues-*folders - For each locale, if
strings.xmldoesn't exist it creates the file first, then sends your full English XML to the LLM with a prompt that instructs it to translate naturally, preserve all XML structure, and never touch format specifiers like%1$sor%d - Writes the translated
strings.xmldirectly into each locale folder - Waits 5 seconds between each language request to avoid hitting API rate limits
Defaults used when you don't specify anything:
| What | Default |
|---|---|
| Provider | Gemini |
| Model | gemini-2.5-flash |
| Source directory | app/src/main/res |
| Delay between requests | 5 seconds |
| App context | none (generic prompt) |
Nothing is modified unless the translation comes back with valid XML. If a request fails, that language is skipped and logged — other languages continue.
Setup
The only requirement is that app/src/main/res/values/strings.xml exists — your English source file.
For target languages, you have two options:
Option A — let the tool create everything:
android-localise translate --api-key YOUR_KEY --languages hi,es,fr,de
This creates values-hi/, values-es/, values-fr/, values-de/ folders and their strings.xml files automatically, then translates into each one.
Option B — pre-create folders yourself:
app/src/main/res/
├── values/ ← your English source (must exist)
│ └── strings.xml
├── values-hi/ ← empty folder is fine
├── values-es/
└── values-fr/
Run android-localise translate --api-key YOUR_KEY and it picks up any values-* folder it finds, creating strings.xml inside each one if it doesn't exist yet.
Get a free API key: Google Gemini AI Studio → Get API Key. The free tier handles most apps without hitting limits.
Commands
translate
android-localise translate --api-key YOUR_KEY
Add --app-context with a one-line description of your app. This meaningfully improves translation quality — the model knows whether "record" means a music track, a health log, or a database entry:
android-localise translate \
--api-key YOUR_KEY \
--app-context "a workout tracking app for gym beginners"
All flags:
| Flag | What it does | Default |
|---|---|---|
--api-key |
Your API key | reads from env var |
--provider |
Which AI to use: gemini openai anthropic custom |
gemini |
--model |
Specific model to use | see Providers |
--languages |
Comma-separated language codes — creates folders and files automatically | — |
--app-context |
One-line description of your app | — |
--res-dir |
Path to your res/ folder |
app/src/main/res |
--base-url |
API endpoint for local/custom providers | — |
--sleep |
Seconds to wait between language requests | 5.0 |
fix
android-localise fix
LLMs occasionally produce output that looks correct but breaks the Android build — curly apostrophes (') instead of escaped ones (\'), unescaped double quotes, or mangled % signs. This command scans every translated strings.xml and corrects these silently.
Always run this before verify and before building.
verify
android-localise verify
Takes every translated string that contains a format specifier (%1$s, %d, %1$f, etc.) and calls String.format() on it using Java's actual runtime. If a translated string would throw UnknownFormatConversionException or MissingFormatArgumentException in your app, this catches it before your users do.
Requires javac in your PATH. If you don't have it system-wide, run this from the Terminal tab inside Android Studio — it ships with a JDK.
models
android-localise models # all providers
android-localise models --provider openai # one provider
Lists every available model and fallback for each provider.
Providers
By default the tool uses Gemini with gemini-2.5-flash. You can switch providers with --provider and optionally pin a specific model with --model.
| Provider | Default model | Fallbacks | API key env var |
|---|---|---|---|
gemini (default) |
gemini-2.5-flash |
gemini-2.0-flash → gemini-1.5-flash → gemini-1.5-pro |
GEMINI_API_KEY |
openai |
gpt-4o-mini |
gpt-4o → gpt-3.5-turbo |
OPENAI_API_KEY |
anthropic |
claude-3-5-haiku-latest |
claude-3-5-sonnet-latest → claude-3-opus-latest |
ANTHROPIC_API_KEY |
custom |
set with --model |
none | — |
If the default model returns a "model not found" error (e.g. it was deprecated), the tool automatically retries with the next fallback. If you pin a model with --model, no fallback is used.
Using OpenAI:
android-localise translate --provider openai --api-key YOUR_KEY
android-localise translate --provider openai --model gpt-4o --api-key YOUR_KEY
Using Anthropic:
android-localise translate --provider anthropic --api-key YOUR_KEY
Using a local model (no API key needed):
# Ollama
android-localise translate \
--provider custom \
--base-url http://localhost:11434/v1/chat/completions \
--model llama3
# LM Studio
android-localise translate \
--provider custom \
--base-url http://localhost:1234/v1/chat/completions \
--model mistral
Environment variables
Set your API key as an env variable so you don't have to pass it every time:
# macOS / Linux
export GEMINI_API_KEY=your_key
# Windows PowerShell
$env:GEMINI_API_KEY = "your_key"
Then just run:
android-localise translate
| Variable | Used by |
|---|---|
GEMINI_API_KEY |
--provider gemini |
OPENAI_API_KEY |
--provider openai and --provider custom |
ANTHROPIC_API_KEY |
--provider anthropic |
Full workflow example
# First time setup — create locale folders
mkdir -p app/src/main/res/values-hi
mkdir -p app/src/main/res/values-es
mkdir -p app/src/main/res/values-de
# Set your key once
export GEMINI_API_KEY=your_key
# Translate, fix, verify
android-localise translate --app-context "a habit tracking app"
android-localise fix
android-localise verify
# Build your app as usual
./gradlew assembleDebug
After this, whenever you add or change strings in your English strings.xml, run the same three commands again. Existing translated strings will be overwritten with fresh translations.
Roadmap
- iOS support — translate
Localizable.stringsandLocalizable.xcstringsfor iOS/macOS apps. The LLM prompt and provider logic is already in place — it mainly needs a parser for Apple's strings format and the right folder structure (<lang>.lproj/). Good first contribution if you're familiar with iOS projects.
Contributing
Bug reports and pull requests are welcome. For larger changes, open an issue first.
git clone https://github.com/BharathKmalviya/android-llm-localization
cd android-llm-localization
pip install -e .
Releases are automated via GitHub Actions — bump the version in pyproject.toml and __init__.py, update CHANGELOG.md, and push to master.
License
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 android_localisation-1.0.4.tar.gz.
File metadata
- Download URL: android_localisation-1.0.4.tar.gz
- Upload date:
- Size: 19.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
adb4155177d42d763ffdefab024bb40a7b6463cb5a4272913b387197bb79f63b
|
|
| MD5 |
fe61c53da007a5aab0d06e4a529434fd
|
|
| BLAKE2b-256 |
a73ef6d8d9cb5ebf4204c14d2edb23b7735a66a093b02da4af9668bd9517c4ac
|
Provenance
The following attestation bundles were made for android_localisation-1.0.4.tar.gz:
Publisher:
publish.yml on BharathKmalviya/android-llm-localization
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
android_localisation-1.0.4.tar.gz -
Subject digest:
adb4155177d42d763ffdefab024bb40a7b6463cb5a4272913b387197bb79f63b - Sigstore transparency entry: 1060322248
- Sigstore integration time:
-
Permalink:
BharathKmalviya/android-llm-localization@14ccceafa70b66fe80155869e42ad3cbf34c563e -
Branch / Tag:
refs/heads/master - Owner: https://github.com/BharathKmalviya
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@14ccceafa70b66fe80155869e42ad3cbf34c563e -
Trigger Event:
push
-
Statement type:
File details
Details for the file android_localisation-1.0.4-py3-none-any.whl.
File metadata
- Download URL: android_localisation-1.0.4-py3-none-any.whl
- Upload date:
- Size: 18.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
50386678009eab5c4710a614aa0620dc46f5e7ea165c2de3ce7e75e3329ee79c
|
|
| MD5 |
8069da71025f2cab3fd9007df72517f3
|
|
| BLAKE2b-256 |
0c099dc2a988bf68667777b2c90ef704ab36110b0da29743bedd16660236dd0f
|
Provenance
The following attestation bundles were made for android_localisation-1.0.4-py3-none-any.whl:
Publisher:
publish.yml on BharathKmalviya/android-llm-localization
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
android_localisation-1.0.4-py3-none-any.whl -
Subject digest:
50386678009eab5c4710a614aa0620dc46f5e7ea165c2de3ce7e75e3329ee79c - Sigstore transparency entry: 1060322313
- Sigstore integration time:
-
Permalink:
BharathKmalviya/android-llm-localization@14ccceafa70b66fe80155869e42ad3cbf34c563e -
Branch / Tag:
refs/heads/master - Owner: https://github.com/BharathKmalviya
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@14ccceafa70b66fe80155869e42ad3cbf34c563e -
Trigger Event:
push
-
Statement type: