From ae06cb4b9b87d7f9ba1f4aab96bd5fe71ed1f6fb Mon Sep 17 00:00:00 2001 From: Kevin Veen-Birkenbach Date: Mon, 19 Oct 2026 12:56:40 +0200 Subject: [PATCH] fix(i18n): take a catalog's language from its path, not its header reason() calls itself the single source of truth for both ends of the pipeline, and the write path honoured that: client.py:228 passes the directory code into unmask(). Only damaged() read catalog.locale, so for 50 catalogs the two ends judged against different languages. 44 catalogs carry no locale header, 8 of them non-Latin and therefore silently past the script check. 6 more name a code their directory disagrees with, so tl was judged as fil, bh as bho, tw as ak. The language becomes a required parameter; both production callers already held the code. Measured over every catalog, header language against path language, one moves: core/av from 0 to 29. Those 29 hold pseudo-Norwegian and a degeneration loop in a Cyrillic catalog, and make i18n-prune has since cleared them. Co-Authored-By: Claude Opus 5 (1M context) --- cli/build/i18n/__main__.py | 2 +- tests/integration/i18n/test_catalogs_complete_on_gpu.py | 4 +++- tests/unit/python/utils/i18n/test_translate.py | 6 +++--- utils/i18n/translate.py | 9 +++++++-- 4 files changed, 14 insertions(+), 7 deletions(-) diff --git a/cli/build/i18n/__main__.py b/cli/build/i18n/__main__.py index b45d382246..5a1c9d8b91 100644 --- a/cli/build/i18n/__main__.py +++ b/cli/build/i18n/__main__.py @@ -125,7 +125,7 @@ def prune(domains: list[str], requested: list[str]) -> int: catalog = read_catalog(path) shared = over_shared(catalog) discard(shared) - broken = damaged(catalog) + broken = damaged(catalog, code) discard(broken) if not shared and not broken: continue diff --git a/tests/integration/i18n/test_catalogs_complete_on_gpu.py b/tests/integration/i18n/test_catalogs_complete_on_gpu.py index 0a7a2e061b..e3f56b7185 100644 --- a/tests/integration/i18n/test_catalogs_complete_on_gpu.py +++ b/tests/integration/i18n/test_catalogs_complete_on_gpu.py @@ -44,7 +44,9 @@ def measure(task: tuple[str, str]) -> Counts: """ name, path = task catalog = read_catalog(Path(path)) - return Counts(name, len(pending(catalog)), len(damaged(catalog))) + return Counts( + name, len(pending(catalog)), len(damaged(catalog, name.split("/")[1])) + ) @unittest.skipUnless(accelerated(), "no NVIDIA runtime on this host") diff --git a/tests/unit/python/utils/i18n/test_translate.py b/tests/unit/python/utils/i18n/test_translate.py index 4cc92948d9..f054a92523 100644 --- a/tests/unit/python/utils/i18n/test_translate.py +++ b/tests/unit/python/utils/i18n/test_translate.py @@ -323,7 +323,7 @@ class TestDamagedMarkup(unittest.TestCase): "Siehe [den Leitfaden]](docs/guide.md) zuerst.", ) - self.assertEqual(len(damaged(catalog)), 1) + self.assertEqual(len(damaged(catalog, "de")), 1) def test_a_dropped_bracket_is_damage(self): catalog = self._catalog( @@ -331,7 +331,7 @@ class TestDamagedMarkup(unittest.TestCase): "!Logo](assets/img/logo.png)", ) - self.assertEqual(len(damaged(catalog)), 1) + self.assertEqual(len(damaged(catalog, "de")), 1) def test_an_intact_translation_is_not_damage(self): catalog = self._catalog( @@ -339,7 +339,7 @@ class TestDamagedMarkup(unittest.TestCase): "Siehe [den Leitfaden](docs/guide.md) zuerst.", ) - self.assertEqual(damaged(catalog), []) + self.assertEqual(damaged(catalog, "de"), []) class TestDuplicateTranslation(unittest.TestCase): diff --git a/utils/i18n/translate.py b/utils/i18n/translate.py index 921ad2a7e6..cca83e8c2c 100644 --- a/utils/i18n/translate.py +++ b/utils/i18n/translate.py @@ -103,7 +103,7 @@ def pending(catalog: Catalog) -> list[Message]: ] -def damaged(catalog: Catalog) -> list[Message]: +def damaged(catalog: Catalog, language: str) -> list[Message]: """Return the entries whose translation altered a protected span or the markup around it. A tightened protection rule turns silently corrupted translations - a @@ -112,10 +112,15 @@ def damaged(catalog: Catalog) -> list[Message]: what masking cannot: a bracket the translator added or dropped next to a protected span leaves every span intact and still breaks the link. + The language is the caller's, never ``catalog.locale``: 44 catalogs carry + no locale header at all, and 6 more name a code the directory disagrees + with (``tl`` holds ``fil_PH``), so reading it there turns the script check + into a no-op for exactly the catalogs nothing else guards. + Args: catalog: a language catalog. + language: the ISO code the catalog's path names. """ - language = str(catalog.locale or "").split("_")[0] return [ message for message in catalog