gettext-translator-service
Plugin interface for gettext-translator: the TranslatorService base class, the plugin loader and helpers to write backends.
Writing a plugin
A plugin is a package that subclasses TranslatorService and registers it under the gettext_translator_service.plugins entry point group. The entry point name is the value of --backend.
[project.entry-points."gettext_translator_service.plugins"]
mybackend = "gettext_translator_mybackend:TranslatorMyBackend"
The options in the YAML file given with --config are available as attributes of self.config, along with the command line options (src and dst are langcodes Language objects). Values like "env:MY_VAR" are read from the environment. Options listed in REQUIRES_CONFIG are checked before the plugin runs.
from gettext_translator_service import TranslatorService, translate_llm
class TranslatorMyBackend(TranslatorService):
REQUIRES_CONFIG: list[str] = ["apikey", "model"]
def configure(self):
# Called once, before translate(): connect, load the model...
self.client = MyClient(self.config.apikey)
def call(self, system_prompt, user_message):
return self.client.complete(self.config.model, system_prompt, user_message)
def translate(self, items):
return translate_llm(items, self.config, self.call)
The translate() contract
translate() receives a list of items, one per unique string:
{"n": 0, "id": "Open"}
{"n": 1, "id": "Payment", "ctx": "Invoice"}
{"n": 2, "id": "One file", "plural": "%d files", "nplurals": 2}
and returns a list of results, in any order, referring to the items by n:
{"n": 0, "msgstr": "Öffnen"}
{"n": 2, "msgstr_plural": ["Eine Datei", "%d Dateien"]}
Items that couldn't be translated may be left out. gettext-translator validates every result (placeholders, HTML tags, number of plural forms) and discards the invalid ones.
Helpers
translate_llm(items, settings, call): for LLM backends. Builds the prompt, sends the items in batches of 100 throughcall(system_prompt, user_message) -> strand parses the JSON answers.translate_plain(items, translate_strings): for machine translation backends that translate plain strings and know nothing about plurals.translate_stringsreceives a list of{"id", "ctx"?}and returns the translations in the same order (Nonefor failures).parse_json_response(text): parses an LLM answer, tolerating<think>blocks and Markdown fences.
License
Copyright (C) 2026 Rodolfo González González.
Licensed under GPL 3.0.
Metadata
Release files for gettext-translator-service 0.1.0
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_service-0.1.0.tar.gz | 5.5 kB | Without provenance | Details for gettext_translator_service-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| gettext_translator_service-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for gettext_translator_service-0.1.0-py3-none-any.whl |
Total release size: 13.4 kB
Release files / gettext_translator_service-0.1.0.tar.gz
| Download URL | gettext_translator_service-0.1.0.tar.gz |
|---|---|
| Size | 5.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
5e0209c9f2fcc2f27778fc4a50cdeb9e9a50099903dc99f8a324c98c18dccf47
|
|
BLAKE2b-256 checksum How to use checksums |
7d9ce1d12f3c6afaa9393c559fafcf9cded40bbf51242d6b5dcf974a6e1d9a87
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.8
|
Release files / gettext_translator_service-0.1.0-py3-none-any.whl
| Download URL | gettext_translator_service-0.1.0-py3-none-any.whl |
|---|---|
| Size | 7.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
82001105a8c99016f8aced1c323651485a553dbb58652a9fe09f95e88e12c58b
|
|
BLAKE2b-256 checksum How to use checksums |
19a1060592332593c53d4c1b4c07accc99917e8ab2ea862505c0c759f31826fd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.8
|
Security for gettext-translator-service 0.1.0
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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A 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.