Python · gettext · Django · OpenAI · Anthropic · Gemini · Ollama
llm-localize — LLM translations that can't break your i18n files
An open-source tool that fills in missing translations with an LLM and rejects any that would break placeholders, HTML, links or plurals.
View project ↗Context
LLMs translate prose well, but i18n strings aren't just prose. They carry
placeholders, HTML tags, URLs and plural forms, and a model will happily
rename %(name)s to %(nom)s or drop a <b> tag. One bad string breaks a
page at runtime.
What I built
A translator that sends only untranslated or fuzzy messages to the model, then validates every result before writing it:
- Placeholders (
%s,%(name)s,{name},%1$s,%@) must match the source. - HTML tags keep their names, order and attributes; only text attributes like
altandtitlemay change. - URLs and emails must come back untouched.
- Plurals are generated per plural form of the target language, from the PO
Plural-Formsheader or CLDR rules. ICU messages keep their arguments and cases. - PO files are run through
msgfmt --check, and any entry it rejects is blanked.
A translation that fails a check is dropped and retried on the next run, so nothing broken ever reaches the file. It supports PO, JSON, Android, iOS, XLIFF, Markdown and Word, and new formats plug in as small classes.
It has one dependency (polib) and calls OpenAI, Anthropic, Gemini, xAI or a
local model over plain HTTP, with no provider SDKs. It runs as a CLI or as a
Django app (makemessages --translate).
Outcome
The core has translated CommCare HQ's UI in production for about two years. I extracted it into a standalone package, published it on PyPI, and wrote documentation with tutorials for Django, Flask, React, Vue, Next.js and Angular.