From de29b99a8940d0498d2ea8f9cb11412e16774633 Mon Sep 17 00:00:00 2001 From: Kevin Veen-Birkenbach Date: Sun, 25 Oct 2026 09:49:19 +0100 Subject: [PATCH] fix(i18n): keep letter-digit names like S3 and OAuth2 whole MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PROTECTED masked identifiers with an underscore and bare numbers, so S3, OAuth2, POP3 and HTML5 went to the engines as a word plus a separately protected digit. Engines tore them ('Amazon S ilə uyğun ...' for 'S3-compatible') or glued the digit onto another word ('Distribuid3-compatible'); the masking audit over core found 159 such entries. A letter-digit token is now one protected span, ahead of the bare-number alternative. The client masks it whole, and damage.reason() condemns a translation that lost or moved it, so prune and retranslation pick those entries up. Co-Authored-By: Claude Opus 5.5 --- tests/unit/python/utils/i18n/test_damage.py | 18 ++++++++++++++++++ .../python/utils/i18n/test_placeholders.py | 5 +++++ utils/i18n/spans.py | 1 + 3 files changed, 24 insertions(+) diff --git a/tests/unit/python/utils/i18n/test_damage.py b/tests/unit/python/utils/i18n/test_damage.py index 1f97ceef6b..59c28ea0da 100644 --- a/tests/unit/python/utils/i18n/test_damage.py +++ b/tests/unit/python/utils/i18n/test_damage.py @@ -62,6 +62,24 @@ class TestAddedLines(unittest.TestCase): ) +class TestLetterDigitTokens(unittest.TestCase): + """A name that carries its version digit is one token the translation must keep whole.""" + + SOURCE: ClassVar[str] = "S3-compatible object storage shared by the roles" + + def test_a_token_torn_from_its_digit_is_condemned(self) -> None: + answer = "Amazon S ilə uyğun obyekt saxlama, rollar arasında paylaşılan" + self.assertEqual(reason(self.SOURCE, answer, "az"), "protected-span") + + def test_a_token_moved_onto_another_word_is_condemned(self) -> None: + answer = "Distribuid3-compatible obyekt stora agaaniin share" + self.assertEqual(reason(self.SOURCE, answer, "aa"), "protected-span") + + def test_a_rendering_keeping_the_token_is_kept(self) -> None: + answer = "S3-kompatibler Objektspeicher, den die Rollen teilen" + self.assertEqual(reason(self.SOURCE, answer, "de"), "") + + class TestWrongNonLatinScript(unittest.TestCase): """A language written in a non-Latin script came back in another non-Latin one.""" diff --git a/tests/unit/python/utils/i18n/test_placeholders.py b/tests/unit/python/utils/i18n/test_placeholders.py index 34df3c7f47..426aaef02a 100644 --- a/tests/unit/python/utils/i18n/test_placeholders.py +++ b/tests/unit/python/utils/i18n/test_placeholders.py @@ -152,6 +152,11 @@ class TestIdentifiersStayIntact(unittest.TestCase): self.assertIn("{% if enabled %}", masked.spans) + def test_a_letter_digit_token_is_masked_whole(self): + masked = mask("Serves OAuth2 and POP3 over an S3-compatible store in HTML5.") + + self.assertEqual(masked.spans, ("OAuth2", "POP3", "S3", "HTML5")) + def test_prose_without_an_underscore_stays_translatable(self): source = "The deploy writes a file to the host and then restarts it." diff --git a/utils/i18n/spans.py b/utils/i18n/spans.py index bb97c8f57c..f5899de67a 100644 --- a/utils/i18n/spans.py +++ b/utils/i18n/spans.py @@ -33,6 +33,7 @@ PROTECTED = re.compile( r"|(?\s]*>[\w.-]*)*\"|'[\w.-]*(?:<[^>\s]*>[\w.-]*)*'" r"|\d+(?:[.,]\d+)*" r"|\*\*|\*|`|\[|\]|\{|\}|\(|\)|\""