Skip to content

imp: i18n: ignore user catalog translations with wrong placeholders, with a warning - #2760

Merged
simonmichael merged 1 commit into
mainfrom
i18n-placeholder-check
Oct 1, 2026
Merged

simonmichael merged 1 commit into
mainfrom
i18n-placeholder-check

Conversation

@simonmichael

Copy link
Copy Markdown
Member

A translation in a user catalog (~/.config/hledger/locale/LANG.po) that doesn't have exactly its English text's {placeholders} is now ignored, with a warning naming each such translation. The built-in translation, or the English text, is shown instead, and the rest of the catalog is still used.

Before, such a translation was used as is. A report title could silently lose its dates, or show a misspelled placeholder literally. For example, a German catalog translating the title template as "{bogus} {report}" gave:

{bogus} Bilanz

Now it gives:

Warning: translation catalog …/hledger/locale/de.po: ignoring translations whose {placeholders} differ from the English text's:
  "{report} {dates}{clarification}{valuation}": the translation has {bogus} {report}, but the English text has {clarification} {dates} {report} {valuation}
Bilanz 2008-12-31

Poedit and Weblate already warn about missing placeholders; this covers catalogs edited by hand, which doc/TRANSLATING.md says is fine.

Details:

  • The rule is the one the unit tests already applied to the built-in catalogs: a translation must have exactly the English text's placeholders, and a plural form may have only those plus {n}. It's now one function, used both when loading a user catalog and by the built-in catalogs' unit test.
  • A plural entry's first form is also stored as an ordinary message. It is judged only by the plural rule, so a valid plural whose singular uses {n} isn't rejected, and a bad plural entry is removed from both places.
  • doc/TRANSLATING.md explains the check and the new warning.

Tests: a new unit test covers good and bad messages and plurals and the warning text. Unit tests, hledger/test/i18n.test and just i18n-check pass. A functional test would need a small catalog fixture used through XDG_CONFIG_HOME; I can add one if wanted.

AI usage: Claude Opus 5.5, ~18k output tokens

…ignored, with a warning

A translation in a user catalog (~/.config/hledger/locale/LANG.po) that
does not have exactly its English text's {placeholders} is now ignored,
and hledger warns, naming each such translation and its placeholders.
The built-in translation, or the English text, is shown instead, and the
rest of the catalog is still used. Before, such a translation was used
as is, silently dropping filled-in values (a report title lost its
dates) or showing a misspelled placeholder literally ("{bogus} Bilanz").
Poedit and Weblate already warn about this; this covers catalogs edited
by hand.

A plural form may have only its English text's placeholders and {n}.
The built-in catalogs' unit test now uses the same check.

AI usage: Claude Opus 5.5, ~18k output tokens
@simonmichael simonmichael added the i18n Internationalisation/localisation-related. label Sep 30, 2026
@simonmichael
simonmichael merged commit b50e114 into main Oct 1, 2026
2 checks passed
@simonmichael
simonmichael deleted the i18n-placeholder-check branch October 1, 2026 01:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

i18n Internationalisation/localisation-related.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant