Skip to main content

Zero-dependency Android strings.xml translation and verification using LLMs (Gemini, OpenAI, Anthropic, Ollama).

Project description

Android LLM Localization

PyPI version Python 3.8+ License: MIT

A zero-dependency Python tool to translate, fix, and verify Android strings.xml resources using Large Language Models (LLMs) — Gemini, OpenAI, Anthropic (Claude), or any local model via Ollama.

Why this exists?

Localizing Android apps usually involves paying for services, exporting CSVs, or manually using Google Translate. This tool translates strings.xml directly in your project using modern LLMs, giving significantly better context-aware translations.

Zero dependencies — no pip install of extra libraries required. Uses only Python's built-in networking.


Installation

pip install android-localisation

To update to the latest version:

pip install --upgrade android-localisation

Quick Start

# 1. Translate (Gemini free tier recommended)
android-localise translate --api-key YOUR_GEMINI_API_KEY

# 2. Fix any XML escaping issues introduced by the LLM
android-localise fix

# 3. Verify no format specifiers were corrupted (requires Java JDK)
android-localise verify

The Three Commands

1. translate — Translate strings into all locale directories

Reads app/src/main/res/values/strings.xml (English) and writes translated strings.xml into every values-* directory it finds.

Prerequisites:

  • Create empty values-<lang>/ folders for each language you want (e.g. values-hi/, values-es/)
  • Get an API key — Google Gemini AI Studio has a generous free tier
# Basic — Gemini (default)
android-localise translate --api-key YOUR_GEMINI_API_KEY

# With app context for better translations
android-localise translate --api-key YOUR_KEY --app-context "a fitness tracking app"

# OpenAI
android-localise translate --api-key YOUR_KEY --provider openai --model gpt-4o

# Anthropic (Claude)
android-localise translate --api-key YOUR_KEY --provider anthropic

# Local model via Ollama
android-localise translate --provider custom --base-url http://localhost:11434/v1/chat/completions --model llama3

Full arguments:

Argument Description Default
--api-key API key (or set GEMINI_API_KEY, OPENAI_API_KEY, ANTHROPIC_API_KEY env vars) None
--provider AI provider: gemini, openai, anthropic, custom gemini
--model Model name (e.g. gemini-2.5-flash, gpt-4o, claude-3-5-sonnet-latest) provider default
--app-context Short description of your app to improve translation quality None
--res-dir Path to the Android res/ directory app/src/main/res
--base-url Base URL for custom OpenAI-compatible endpoints None
--sleep Seconds between requests to avoid rate limits 5.0

2. fix — Fix XML escaping issues

LLMs occasionally introduce malformed characters — curly apostrophes ('), unescaped quotes, or broken % symbols. This command cleans them all up.

android-localise fix
# or with a custom res dir:
android-localise fix --res-dir path/to/res

3. verify — Catch format specifier crashes before they happen

LLMs can corrupt Android format specifiers like %1$s or %d, which causes UnknownFormatConversionException crashes at runtime. This command compiles a Java verifier and dry-runs String.format() against every translated string.

android-localise verify

Requires javac in your system PATH. Run from Android Studio's terminal if needed.


Recommended Workflow

  1. Update your English strings.xml
  2. Create empty values-<lang>/ folders for the languages you want
  3. android-localise translate --api-key YOUR_KEY
  4. android-localise fix
  5. android-localise verify
  6. Build and test your app

Supported Providers

Provider Default Model API Key Env Var
gemini (default) gemini-2.5-flash GEMINI_API_KEY
openai gpt-4o-mini OPENAI_API_KEY
anthropic claude-3-5-sonnet-latest ANTHROPIC_API_KEY
custom (must specify) OPENAI_API_KEY or none


Contributing

Issues and PRs welcome at github.com/BharathKmalviya/android-llm-localization.


Created to make Android localization accessible, free, and completely automated.

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

android_localisation-1.0.0.tar.gz (14.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

android_localisation-1.0.0-py3-none-any.whl (15.1 kB view details)

Uploaded Python 3

File details

Details for the file android_localisation-1.0.0.tar.gz.

File metadata

  • Download URL: android_localisation-1.0.0.tar.gz
  • Upload date:
  • Size: 14.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.2

File hashes

Hashes for android_localisation-1.0.0.tar.gz
Algorithm Hash digest
SHA256 5adb6d1dac9802beddd5e17b3261e66be6f737ee20477521cbec2bcb699ad8e6
MD5 4fcd34837934da1e78901652089cef8c
BLAKE2b-256 2e81a0a1cbe60c539a91f297f7d97c277981a9cee2ab046525cfdcbe172c9a7a

See more details on using hashes here.

File details

Details for the file android_localisation-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for android_localisation-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 17016ae89cd2a4453c988e79ef63347be0e475901ab1a9437e277fcb6f822b9f
MD5 56092ab75e5b895cdac919655d656ad5
BLAKE2b-256 ca1a58ff69b88bdd88fec36afb3157a7ae11a3c6aee3b2898f826394af88ed2e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page