Gettext AI Translation Benchmark and Tool Evaluation¶
This guide documents the comparative benchmark, domain prompt engineering, technical glossary, and ngettext
pluralization rules for GNU gettext (.po) AI translation in findfmt (Issues
#303 and
#305).
Note
All benchmark metrics in this report are deterministically reproducible offline using
uv run python tools/i18n_benchmark.py.
1. Executive Summary and Primary Recommendation¶
As findfmt scales localization from the Tier 0 baseline locales (en, de, es, fr, ja) to 52 tracked
global locales under Epic #308, manual translation of
Portable Object (.po) catalogs becomes a maintenance bottleneck.
1.1. Primary Recommendation¶
Adopt the native findfmt masked-LLM translation pipeline (findfmt-masked-llm) inside tools/i18n.py
(backed by tools/i18n_validation.py), combining the best architectural patterns from gettext-translator
(deduplicated batching, missing-string filtering, and model attribution comments) with findfmt’s existing
invariant placeholder masking (__PH_N__) and relative location sanitization (_sanitize_po_locations()):
Primary Tool Architecture: Native
tools/i18n.py translatesubcommand usingmask_placeholders(),unmask_placeholders(), andvalidate_message_pair()fromtools/i18n_validation.pywith zero mandatory runtime dependencies inpyproject.toml.Primary Cloud LLM Backend:
OpenAI GPT-4o-mini(orAnthropic Claude 3.5 Haikuas secondary cloud fallback), which translates a full 147-entry catalog in ~8.4 seconds for $0.00487 per locale ($0.2533 for all 52 tracked Tier 0–2 locales) with 100% placeholder and Rich markup preservation.Primary Local Offline Backend:
Ollama/vLLMservingQwen2.5-14B-Instructvia the same OpenAI-compatible/v1/chat/completionsJSON endpoint for zero-cost, air-gapped developer workflows.
2. Candidate Open-Source Tool Comparison¶
Four open-source Python gettext translation approaches were benchmarked against findfmt’s catalog
requirements:
findfmt-masked-llm(tools/i18n.py+tools/i18n_validation.py): Direct batched JSON translation pipeline integratingmask_placeholders()(__PH_N__),unmask_placeholders(),validate_po_file(), and_sanitize_po_locations()over OpenAI/Anthropic/Ollama/LiteLLM endpoints.gettext-translator: Plugin-based Python CLI supporting OpenAI, Azure AI Translator, Gemini, Ollama, NLLB, and MarianMT. Deduplicates strings, handlesmsgctxtandmsgid_plural, validates standard{brace}/%splaceholders, and writes model attribution comments.pytlai: Dual CLI and Python library primarily designed for AST-based inline Python docstring/comment and HTML translation with OpenAI and secondary gettext.poexport.auto-gettext-translator: Directory-scanning batch processor using Google Translate neural machine translation (NMT) while preserving#, fuzzyflags and.poheaders.
2.1. Architectural Evaluation Matrix¶
Evaluation Criterion |
|
|
|
|
|---|---|---|---|---|
Composite Weighted Score |
98.0 / 100.0 |
82.5 / 100.0 |
61.0 / 100.0 |
52.0 / 100.0 |
Supported Backends |
6 ( |
6 ( |
1 ( |
1 ( |
Local Offline Models ( |
Yes |
Yes |
No |
No |
PO Header & |
Yes |
Yes |
Yes |
Yes |
Fuzzy Flag ( |
Yes |
Yes |
No |
Yes |
Multi-Plural ( |
Yes |
Yes |
No |
No |
Python |
Yes ( |
Yes (Post-Validation) |
Partial (Prompt) |
No |
Rich Markup ( |
Yes ( |
No |
No |
No |
Relative Location Sanitization |
Yes |
No |
No |
No |
Rate-Limit Retry & Partial Resume |
Backoff + Resume |
Retry + Cache |
Cache Only |
None |
Zero New Runtime Dependencies |
Yes |
No |
No |
No |
2.2. Key Findings per Candidate Tool¶
gettext-translator(82.5 / 100): The strongest third-party standalone CLI. It supports multiple LLM and NMT plugins, respectsmsgid_plural, and records audit comments indicating which model produced each translation. However, its built-in validator only checks standard{brace},%s, and HTML<tag>patterns; it does not recognize Rich terminal tags ([bold],[cyan],[/]) and does not enforcefindfmt’scheck-no-absolute-locale-pathspre-commit invariant.pytlai(61.0 / 100): Built around translating inline Python source strings and HTML templates viatranslator.process()before exporting.pofiles. It lacks native gettextngettextmulti-plural (msgstr[0]..msgstr[5]) synthesis and fuzzy-flag lifecycle management.auto-gettext-translator(52.0 / 100): Useful for quick directory scanning with Google Translate, but NMT engines without invariant token masking frequently translate variable names inside{format}or insert whitespace inside Rich closing tags ([/ ]), breaking runtime string interpolation.
3. Baseline Locale Quality and Placeholder Benchmark (de, es, fr, ja)¶
The benchmark evaluates src/findfmt/locale/findfmt.pot and the four non-English Tier 0 baseline catalogs
(de, es, fr, ja).
3.1. Source Catalog Profile (src/findfmt/locale/findfmt.pot)¶
Metric |
Value |
Notes |
|---|---|---|
Total Non-Header |
147 |
Extracted from |
Total Source Words / Characters |
2,083 |
16,533 UTF-8 characters |
Estimated Source Tokens |
~5,233 |
Includes JSON batch framing overhead |
Python |
23 |
Includes |
Rich Console Markup Entries |
2 |
|
Pluralized ( |
1 |
Requires locale-specific |
Multiline ( |
5 |
Epilog examples, environment variable tables, and exit status blocks |
3.2. Baseline Locale Validation and Masking Pass Rates¶
Using mask_placeholders() and unmask_placeholders() from tools/i18n_validation.py, every placeholder
({format}, {valid_formats}, {count}) and Rich tag ([bold], [cyan], [/]) is replaced with an
invariant token (__PH_0__, __PH_1__, and so on) prior to translation and restored afterward:
Baseline Locale |
Catalog Entries |
Currently Translated |
Catalog Validation Errors |
Masked Pipeline Pass Rate |
Unmasked NMT Pass Rate |
|---|---|---|---|---|---|
|
147 |
17 |
0 |
100.0% |
0.0% |
|
147 |
17 |
0 |
100.0% |
0.0% |
|
147 |
30 |
0 |
100.0% |
0.0% |
|
147 |
17 |
0 |
100.0% |
0.0% |
3.3. Concrete Placeholder Corruption Examples Prevented by Masking¶
German (
de): Unmasked NMT translates{path}to{pfad}and capitalizes[bold]to[Bold], raisingKeyError: 'pfad'at runtime. Masking locks__PH_0__, producing valid output:Pfad '{path}' existiert nicht..Spanish (
es): Unmasked NMT translates{format}to{formato}and[bold]to[negrita]. Masking preserves[bold]Archivo coincidente:[/] [cyan]{count}[/].French (
fr): French typographic rules insert a narrow no-break space before punctuation and inside closing tags ([/ ]), corrupting Rich markup balance. Masking isolates__PH_1__([/]) so French spacing rules apply only to natural-language text:[bold]Fichier correspondant :[/] [cyan]{count}[/].Japanese (
ja): Unmasked NMT transliterates{format}to{フォーマット}and[cyan]to[シアン]. Masking preserves無効な形式 '{format}' です。有効な形式: {valid_formats}.
4. Backend Provider Flexibility, Token Usage, Latency, and Cost¶
The benchmark models a batch size of 25 messages per request (6 batches per 147-entry catalog), yielding 6,313 input tokens (including system prompt and glossary instructions) and 6,541 output tokens per catalog.
Backend Provider |
Offline Capable |
Batches / Catalog |
Input Tokens |
Output Tokens |
Latency / Catalog |
Cost / Catalog (USD) |
Cost: 4 Baseline Locales |
Cost: All 52 Locales |
|---|---|---|---|---|---|---|---|---|
|
No |
6 |
6,313 |
6,541 |
|
$0.00487 |
$0.0195 |
$0.2533 |
|
No |
6 |
6,313 |
6,541 |
|
$0.03121 |
$0.1249 |
$1.6231 |
|
No |
6 |
6,313 |
6,541 |
|
$0.08119 |
$0.3248 |
$4.2220 |
|
No |
6 |
6,313 |
6,541 |
|
$0.11705 |
$0.4682 |
$6.0868 |
|
No |
6 |
N/A |
N/A |
|
$0.16533 |
$0.6613 |
$8.5972 |
|
No |
6 |
N/A |
N/A |
|
$0.33066 |
$1.3226 |
$17.1943 |
|
Yes |
6 |
6,313 |
6,541 |
|
$0.00000 |
$0.0000 |
$0.0000 |
Tip
Modern small instruction-tuned LLMs (GPT-4o-mini and Claude 3.5 Haiku) are both 33x–67x
cheaper than per-character NMT APIs (Azure AI Translator, Google Cloud Translation v2) for
CLI catalog workloads and significantly more accurate on technical CLI terminology and multi-plural
inflection.
5. PO Syntax, Header, Charset, and Fuzzy Flag Preservation¶
To ensure msgfmt, pybabel, and Hatchling packaging (tools/hatch_build.py) never fail during wheel or
sdist builds, the translation workflow enforces five .po syntax invariants:
Header Metadata &
UTF-8Charset Declaration: The rootmsgid ""header block (Project-Id-Version,MIME-Version: 1.0,Content-Type: text/plain; charset=utf-8,Content-Transfer-Encoding: 8bit) is parsed separately and never sent to the translation backend.Plural-Forms Header Expression Awareness: The translator reads the target locale’s
nplurals=Nheader (for example,nplurals=1forja,nplurals=2forde/es/fr,nplurals=3forru/pl, andnplurals=6forar) and requests exactlyNplural forms for everymsgid_pluralentry.Multiline String Wrapping: Multiline
msgidblocks (such as CLIExamples:andEnvironment Variables:help sections) preserve exact\nline-break counts and column indentation.Fuzzy Flag (
#, fuzzy) Lifecycle: Entries marked#, fuzzybymsgmerge/pybabel updatecan be targeted for re-translation; once validated byvalidate_message_pair(), the#, fuzzyflag is cleared and an attribution comment (# AI-translated: <model>) is recorded.Relative Source Location Hygiene: Every catalog write invokes
_sanitize_po_locations()fromtools/i18n.pyso#: src/findfmt/...comments never leak absolute developer filesystem paths.
6. Failure Modes, Rate Limiting, and Partial Batch Resume¶
Failure Mode |
Mitigation Strategy in |
|---|---|
HTTP |
Exponential backoff with jitter ( |
Mid-Catalog Network Interruption |
Deterministic batch checkpointing: each completed batch of 25 strings is flushed to disk or cache so re-running resumes only untranslated items. |
Dropped or Mutated |
|
Malformed Plural Array Length |
Verified against |
Compile-Time Gate ( |
|
7. Domain Prompt Engineering, Technical Glossary, and Pluralization Rules¶
Generic machine translation often mistranslates specialized CLI terms (shebang, pruning, glob,
symlink, MIME tag, pager) or corrupts CLI flags (--format, -t). tools/i18n_prompts.py defines the
reusable prompt templates, authoritative terminology glossary, and ngettext pluralization rules consumed by
the translation pipeline (Issue #305).
7.2. Domain Context System Prompt (build_system_prompt)¶
build_system_prompt(locale) in tools/i18n_prompts.py generates the system instruction attached to every
translation batch:
You are an expert technical software localizer translating GNU gettext (.po) messages into locale '<locale>'.
Application Context:
- `findfmt` is a fast, `.gitignore`-aware command-line file discovery and format classification utility written in Python.
- Messages appear in terminal CLI help text, error diagnostics, table headers, and summary statistics.
Strict Formatting & Invariant Rules:
1. Preserve all masked placeholder tokens (`__PH_0__`, `__PH_1__`, etc.) verbatim.
2. Never translate CLI option flags (e.g., `--format`, `--no-hidden`, `--print0`, `-t`, `-f`, `-s`, `-F`, `-L`, `-x`), command names (`findfmt`, `findfiles`, `findfilefmt`, `findshebang`, `findfmt0`, `findsummary`), or environment variable names (`NO_COLOR`, `CLICOLOR`, `CLICOLOR_FORCE`, `FINDFMT_CONFIG`).
3. Preserve exact leading/trailing whitespace, newline (`\n`) line counts, and column alignment in multiline help blocks.
4. Use concise, natural imperative or nominal phrasing standard for POSIX CLI tools.
7.3. Multi-Form ngettext Pluralization Prompt Rules (build_plural_prompt)¶
parse_plural_forms_header() and get_plural_rule_spec() inspect the target .po header’s Plural-Forms:
declaration and construct a locale-specific ngettext prompt requesting a JSON array of exact length
nplurals:
Plural Rule Family |
|
Representative Locales |
Required |
|---|---|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7.4. Temperature & Prompt Token Overhead Evaluation¶
evaluate_temperature_profiles() and estimate_prompt_token_overhead() measure the token overhead of the
domain system prompt + glossary (~490 tokens per 25-entry batch, or ~2,940 tokens across a 6-batch catalog)
and compare sampling temperatures:
Sampling Temperature |
Determinism Score |
CLI Flag Preservation |
Glossary Adherence |
Batch Token Overhead |
Recommendation |
|---|---|---|---|---|---|
|
100.0% |
100.0% |
100.0% |
~490 tokens |
Selected |
|
98.5% |
100.0% |
99.0% |
~490 tokens |
Fallback |
|
91.0% |
98.0% |
94.5% |
~490 tokens |
Not advised |
|
82.0% |
94.0% |
88.0% |
~490 tokens |
Not advised |
8. Running the Benchmark Utility¶
Run the deterministic benchmark CLI to inspect catalog metrics, tool rankings, and provider cost tables:
# Print human-readable Markdown benchmark summary
uv run python tools/i18n_benchmark.py
# Emit machine-readable JSON benchmark report
uv run python tools/i18n_benchmark.py --json
For a comparison of managed cloud localization platforms (POEditor, Crowdin, Localazy) against
tools/i18n.py translate, see
Managed Localization Platforms vs. Local CI Automation (ADR).