mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2026-11-29 06:17:25 +00:00
fix(i18n): judge a translation by one predicate on both ends
unmask() accepted a translation as soon as protected_spans matched, while damaged() also rejected it for a dropped name, a halved body or changed markup. Three of the four criteria lived only in the gate, so every run wrote entries the gate then condemned, make i18n-prune emptied them and the next run wrote them back. It never converged: ko carries 331 such entries, 3.7 percent of what it has translated, against 0.1 percent or less for Latin scripts. Introduce harms(source, translation) in placeholders.py as the single source of truth and call it from both ends. truncated() and structure() move there with it, since translate.py already imports placeholders and the other direction would be a cycle. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
91a2582ea4
commit
fe80a23725
3 files changed
+101
-40
No files matched your search
@@ -9,15 +9,18 @@ from __future__ import annotations
|
||||
|
||||
import unittest
|
||||
|
||||
from typing import ClassVar
|
||||
|
||||
from utils.i18n.placeholders import (
|
||||
collapse,
|
||||
harms,
|
||||
mask,
|
||||
recapitalise,
|
||||
resegment,
|
||||
terminate,
|
||||
truncated,
|
||||
unmask,
|
||||
)
|
||||
from utils.i18n.translate import truncated
|
||||
|
||||
|
||||
def _round_trip(source: str, translated: str) -> str | None:
|
||||
@@ -145,5 +148,50 @@ class TestTruncated(unittest.TestCase):
|
||||
self.assertFalse(truncated(source, "B" * 180))
|
||||
|
||||
|
||||
class TestWriterAndGateAgree(unittest.TestCase):
|
||||
"""The client must reject exactly what the release gate reports.
|
||||
|
||||
A criterion on one side only makes every run rewrite what the other side
|
||||
then condemns, so `make i18n-prune` and `make i18n-translate` never
|
||||
converge.
|
||||
"""
|
||||
|
||||
SOURCE: ClassVar[str] = (
|
||||
"The deployment registers each service with the reverse proxy and then "
|
||||
"waits until every container reports itself healthy before it continues."
|
||||
)
|
||||
|
||||
def test_the_client_drops_a_translation_the_gate_would_report(self) -> None:
|
||||
halved = "Der Dienst wartet."
|
||||
|
||||
self.assertTrue(harms(self.SOURCE, halved))
|
||||
self.assertIsNone(_round_trip(self.SOURCE, halved))
|
||||
|
||||
def test_the_client_keeps_a_translation_the_gate_accepts(self) -> None:
|
||||
faithful = (
|
||||
"Die Bereitstellung meldet jeden Dienst beim Reverse Proxy an und "
|
||||
"wartet dann, bis jeder Container sich als gesund meldet."
|
||||
)
|
||||
|
||||
self.assertFalse(harms(self.SOURCE, faithful))
|
||||
self.assertEqual(_round_trip(self.SOURCE, faithful), faithful)
|
||||
|
||||
def test_every_criterion_of_the_gate_reaches_the_client(self) -> None:
|
||||
named = "Deploy web-app-docs before the documentation site answers anything."
|
||||
for label, source, translation in (
|
||||
("truncated", self.SOURCE, "Kurz."),
|
||||
("structure", self.SOURCE, f"{self.SOURCE} ["),
|
||||
(
|
||||
"protected span",
|
||||
self.SOURCE,
|
||||
self.SOURCE.replace("reverse proxy", "``rp``"),
|
||||
),
|
||||
("missing name", named, "Stelle die Dokumentationsseite bereit."),
|
||||
):
|
||||
with self.subTest(label):
|
||||
self.assertTrue(harms(source, translation))
|
||||
self.assertIsNone(_round_trip(source, translation))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in new issue
Block a user