Skip to main content

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.

An independently written plugin may use a proprietary license when it uses this library through its interface. The LGPL explicitly treats subclassing a library class as using its interface; changes to the library itself remain subject to the LGPL.

[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 through call(system_prompt, user_message) -> str and parses the JSON answers.
  • translate_plain(items, translate_strings): for machine translation backends that translate plain strings and know nothing about plurals. translate_strings receives a list of {"id", "ctx"?} and returns the translations in the same order (None for 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 LGPL 3.0 or later.

Metadata

Release files for gettext-translator-service 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for gettext-translator-service 0.1.1
File Size Uploaded Provenance Actions
gettext_translator_service-0.1.1.tar.gz 19.4 kB With provenance Details for gettext_translator_service-0.1.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for gettext-translator-service 0.1.1
File Interpreter ABI Platform Actions
gettext_translator_service-0.1.1-py3-none-any.whl Python 3 none any Details for gettext_translator_service-0.1.1-py3-none-any.whl

Total release size: 42.8 kB

Release files / gettext_translator_service-0.1.1.tar.gz

Download URL gettext_translator_service-0.1.1.tar.gz
Size 19.4 kB
Tags Source
SHA-256 checksum
How to use checksums
d9ca629fcceda1d305f714b0031c595dde90a5cdfdaf4e876efae5ae8d5406bf
BLAKE2b-256 checksum
How to use checksums
8f79e7fb4c5c4dca26e1ff688e3a4eac0b81fb9391f5365cd1fb82c77889d341
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 log

Release files / gettext_translator_service-0.1.1-py3-none-any.whl

Download URL gettext_translator_service-0.1.1-py3-none-any.whl
Size 23.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
afc49b34feeefa98b97f2f61ca9493ee8d4132387df9eaf397ceb2d52da7c281
BLAKE2b-256 checksum
How to use checksums
2ecc03a7881e55e77762902fc40a4f70467a926ce8b527dda98fcafd5062b53f
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 log

Security for gettext-translator-service 0.1.1

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.

Select from 2 files

Attestation for gettext_translator_service-0.1.1.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 log

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.

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page