gettext-translator
This program uses several cloud and local AI models to translate gettext PO files.
Features
- Supports several backends, both local HuggingFace models, self-hosted Ollama, and remote API services.
- Extensible. You can write your own translation plugins.
- Translates only the missing entries, of one or many PO files, or whole directories.
- Each unique string is translated once, even if it appears in many files.
- Supports
msgctxtfor better contextual translation, and plural forms (msgid_plural). - Validates the translations: those that lose or change placeholders (
%s,%(name)s,{name}) or HTML tags are discarded, somsgfmt --checkkeeps passing. - Optional cache of translations between runs.
- Dry-run mode, and output to another file or directory.
- Supports tagging of AI-generated translations.
- Supports automatic detection of language.
Backends
See the README.md file in each plugin's directory for examples and information about the backends. Currently this system works with the following backends:
- Azure AI Translator (README): remote API, commercial, API key required.
- OpenAI ChatGPT (README): remote API, several models, commercial, API key required.
- Google Gemini (README): remote API, several models, commercial with a free layer, API key required.
- MarianMT (README): local HuggingFace Helsinki-NLP model, free, auth token might be required.
- NLLB (README): local HuggingFace NLLB model, with noncommercial model weights (CC BY-NC 4.0); auth token might be required.
- Ollama (README): self-hosted (by yourself) Ollama server running free models.
Installation
Python 3.12 or newer is required. Install the program with the backends you want to use:
pip install "gettext-translator[ollama]"
pip install "gettext-translator[chatgpt,gemini]"
pip install "gettext-translator[all]"
From source code
Install the plugin interface, the program and the backends you need, from the root of the repository:
pip install -e translators/gettext-translator-service -e . -e translators/gettext-translator-ollama
General CLI arguments
The command line tool supports the following arguments:
--info: Shows information about the backend.--backend: Which backend to use.--po: One or more .po files or directories. Directories are searched recursively for .po files.--src: The source language. Default: en.--dst: The language to translate to. Files whoseLanguageheader is a different language are skipped.--fuzzy: Remove the fuzzy flag from all the entries before translating.--context: Optional default translation context for msgid without msgctxt.--ascribe: Add anAI-translatedcomment to each translated entry. Existing comments are kept.--config: Path to the YAML configuration file for the backend. Default: config.yaml.--dry-run: Show the translations without saving any file.--output: Save to this .po file (single input file) or directory (keeping the relative paths), instead of overwriting the input files.--cache: Path to a SQLite file where the translations are cached, so they are not requested again in later runs. The cache is specific to the backend, model and languages.--verbose: Show useful information. Possible values: debug, info, warning, error, critical. Default: warning.--version: Shows the version.--help: Shows the help message.
The exit code is 1 if there was an error, or if there were strings to translate but none could be translated.
Per backend configuration
To avoid cluttering of the command line arguments, each backend has its own configuration file, in YAML format. This file contains the backend's-specific options, as described in each plugin's README.md file. Please refer to those files (linked above), or use the --info argument to display the README.md and list the required options for each backend (view usage example below).
Values with the form "env:VARIABLE" are read from the environment variable VARIABLE, which is useful for API keys.
You must specify the path to the configuration file using the --config argument.
A sample configuration file for each backend is provided in each plugin's directory, under translators/gettext-translator-<backend>/<backend>-sample.yaml.
Usage examples
View the README file for the plugin and which options are required for it:
gettext-translator --info --backend chatgpt
Translate using the Azure AI Translator backend:
gettext-translator --backend azure --src es --dst de_DE --config translators/gettext-translator-azure/azure-sample.yaml --po example/messages.po
Translate using the ChatGPT backend, adding a comment attributing translations to AI:
gettext-translator --backend chatgpt --src es --dst de_DE --config translators/gettext-translator-chatgpt/chatgpt-sample.yaml --po example/messages.po --ascribe
Preview the translation of all the German .po files of a project with Ollama, caching the results, and then save them (the second run uses the cache and doesn't call the model again):
gettext-translator --backend ollama --src en --dst de --config ollama.yaml --po locale/ --cache translations.db --dry-run
gettext-translator --backend ollama --src en --dst de --config ollama.yaml --po locale/ --cache translations.db
Plural forms
The number of plural forms is read from the Plural-Forms header of each file (2 if it is missing). LLM backends (ChatGPT, Gemini, Ollama) translate every plural form. The machine translation backends (Azure, MarianMT, NLLB) translate the singular and the plural msgid separately, which is right for languages with two plural forms; for languages with more forms (Russian, Polish, Arabic...) use an LLM backend.
Architecture
This software was designed with extensibility as a priority, so it's not restricted to a single service or provider. It is based on an auto-discovery plugin system, and users can create additional plugins as needed. See gettext-translator-service to write your own.
classDiagram
class TranslatorService {
<<abstract>>
+REQUIRES_CONFIG: list[str]
+config: Settings
+configure()
+translate(items) list[dict]
+show_info()
}
class GettextTranslator {
+translate() bool
}
GettextTranslator --> TranslatorService : uses the plugin chosen with --backend
GettextTranslator --> TranslationCache : --cache
TranslatorService <|-- TranslatorAzure
TranslatorService <|-- TranslatorChatGPT
TranslatorService <|-- TranslatorGemini
TranslatorService <|-- TranslatorMarianMT
TranslatorService <|-- TranslatorNLLB
TranslatorService <|-- TranslatorOllama
Development
make dev # editable install of the packages and the dev tools
make check # lint, tests, build and twine check
Run make help for the other targets.
Releasing
Releases are published to PyPI by the Publish GitHub workflow, using Trusted Publishing.
-
Commit your changes and check that the
CIworkflow passes. -
Bump the version, it is committed as
vX.Y.Z:make bump # 0.1.0 -> 0.1.1 make bump PART=minor # 0.1.0 -> 0.2.0 make bump PART=major # 0.1.0 -> 1.0.0
-
Optionally, publish to TestPyPI first: push the commit (
git push), then run Actions → Publish → Run workflow →testpypi. -
Tag the new version and push it, the
Publishworkflow uploads the packages to PyPI:make release
Run make bump and make release as separate commands, since make reads the version once when it starts.
Only gettext-translator is bumped by make bump. The version of each backend is set by hand in its own pyproject.toml; bump it when the backend changed. Only the packages whose version changed are uploaded.
Notes
- It is recommended that you learn about gettext and the format of PO files. But of course, if you are reading this, you should already know it.
- Why gettext?
- It uses full strings in the source language as keys. This is the most relevant reason, as it means you don't have to search for abstract keys like
page.title.hellooritem.specification. While that approach may work for a few strings, it becomes complicated and chaotic with hundreds or thousands of them. - The original key string is used as a fallback. If a translation doesn't exist, the original string is displayed.
- It's a tried and trusted GNU standard.
- It uses full strings in the source language as keys. This is the most relevant reason, as it means you don't have to search for abstract keys like
- For the example PO file, the best contextual results were obtained using Azure's AI Translator service and the
qwen3:14bmodel in Ollama.
License
Copyright (C) 2026 Rodolfo González González.
Licensed under LGPL 3.0 or later.
Independent translation plugins may be distributed under proprietary licenses. Changes to this project's own code remain subject to the LGPL.
Metadata
Release files for gettext-translator 0.1.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| gettext_translator-0.1.2.tar.gz | 32.0 kB | With provenance | Details for gettext_translator-0.1.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| gettext_translator-0.1.2-py3-none-any.whl | Python 3 | none | any | Details for gettext_translator-0.1.2-py3-none-any.whl |
Total release size: 62.7 kB
Release files / gettext_translator-0.1.2.tar.gz
| Download URL | gettext_translator-0.1.2.tar.gz |
|---|---|
| Size | 32.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0d27f22675d1489f1222d72c27064650712bb649bbf9ad1a3128d6e7889e4ab6
|
|
BLAKE2b-256 checksum How to use checksums |
a50e0e5fbab7856f187c169ed967630183b252e6c4078f2e715e1309425df0ee
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 31, 2026.
Transparency logRelease files / gettext_translator-0.1.2-py3-none-any.whl
| Download URL | gettext_translator-0.1.2-py3-none-any.whl |
|---|---|
| Size | 30.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
4a7e5d020d242b19a7cd64aee49d34d517322af9ff567e747085d6e66d505ef4
|
|
BLAKE2b-256 checksum How to use checksums |
25a8c31aa528bd2974e1ff781e5228cf49a0a9020f5cb2f99aa6cde67bbe4aea
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 31, 2026.
Transparency logSecurity for gettext-translator 0.1.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for gettext_translator-0.1.2.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 31, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.