From 9ee41254edbe402a7d8a01bb414815e7e7695cac Mon Sep 17 00:00:00 2001 From: Dandaedre Date: Fri, 25 Sep 2026 11:44:33 +0200 Subject: [PATCH] Translate report status and severity badges --- docs/report-contract.md | 5 +++- plugins/report/locales.json | 56 +++++++++++++++++++++++++++++++++++-- plugins/report/model.typ | 12 ++++---- tests/test_plugin.py | 25 ++++++++++++++++- 4 files changed, 88 insertions(+), 10 deletions(-) diff --git a/docs/report-contract.md b/docs/report-contract.md index 3a9d925..cb6b7e4 100644 --- a/docs/report-contract.md +++ b/docs/report-contract.md @@ -29,7 +29,10 @@ This translates section headings, timeline column headings, diagnostic labels, report-type labels, default titles, footer labels, and known metadata labels. It also sets Typst's text language. Keep metadata keys such as `Author` and `Date` unchanged. Authored text, explicit titles (including `actions_title`), -custom metadata labels, and status/severity values remain as supplied. +and custom metadata labels remain as supplied. Known status and severity badge +labels are translated through the same catalog; unknown values remain as +supplied. Keep the source status/severity values unchanged so badge colors +retain their meaning. Add any number of languages to [`plugins/report/locales.json`](../plugins/report/locales.json), without changing diff --git a/plugins/report/locales.json b/plugins/report/locales.json index 3b58f7e..0822bc9 100644 --- a/plugins/report/locales.json +++ b/plugins/report/locales.json @@ -34,7 +34,33 @@ "Date": "Date", "Service": "Service", "Environment": "Environment", - "Owner": "Owner" + "Owner": "Owner", + "pending": "pending", + "recommended": "recommended", + "open": "open", + "resolved": "resolved", + "confirmed": "confirmed", + "confirmed-correlation": "confirmed-correlation", + "paused": "paused", + "observing": "observing", + "ongoing": "ongoing", + "conditional": "conditional", + "completed": "completed", + "hold": "hold", + "observed": "observed", + "priority": "priority", + "repaired": "repaired", + "requested": "requested", + "verified": "verified", + "deferred": "deferred", + "critical": "critical", + "high": "high", + "medium": "medium", + "low": "low", + "info": "info", + "warning": "warning", + "ok": "ok", + "success": "success" }, "fr": { "Report": "Rapport", @@ -71,6 +97,32 @@ "Date": "Date", "Service": "Service", "Environment": "Environnement", - "Owner": "Responsable" + "Owner": "Responsable", + "pending": "en attente", + "recommended": "recommandé", + "open": "ouvert", + "resolved": "résolu", + "confirmed": "confirmé", + "confirmed-correlation": "corrélation confirmée", + "paused": "en pause", + "observing": "en observation", + "ongoing": "en cours", + "conditional": "sous condition", + "completed": "terminé", + "hold": "suspendu", + "observed": "observé", + "priority": "prioritaire", + "repaired": "réparé", + "requested": "demandé", + "verified": "vérifié", + "deferred": "reporté", + "critical": "critique", + "high": "élevé", + "medium": "moyen", + "low": "faible", + "info": "information", + "warning": "avertissement", + "ok": "OK", + "success": "réussite" } } diff --git a/plugins/report/model.typ b/plugins/report/model.typ index 4bf6553..0cff517 100644 --- a/plugins/report/model.typ +++ b/plugins/report/model.typ @@ -123,13 +123,13 @@ )[#title], badge( - severity, + t(severity), color: severity-color(theme, severity), ), if status != none { badge( - status, + t(status), color: severity-color(theme, status), ) } else { @@ -312,7 +312,7 @@ badge(id, color: theme-color(theme, "accent")), text(size: 10pt, weight: "bold")[#diagnosis], if status != none { - badge(status, color: severity-color(theme, status)) + badge(t(status), color: severity-color(theme, status)) } else { [] }, @@ -412,7 +412,7 @@ ], badge( - status, + t(status), color: severity-color(theme, status), ), ) @@ -592,7 +592,7 @@ if status != none { badge( - status, + t(status), color: severity-color(theme, status), ) } @@ -603,7 +603,7 @@ if severity != none { badge( - severity, + t(severity), color: severity-color(theme, severity), ) } diff --git a/tests/test_plugin.py b/tests/test_plugin.py index f0909db..42b16a9 100644 --- a/tests/test_plugin.py +++ b/tests/test_plugin.py @@ -43,7 +43,7 @@ class ReportPluginTests(unittest.TestCase): source.write_text(json.dumps(report)) french = self.render_text(source, work) for label, translation in catalog['fr'].items(): - if label == 'Stakeholder briefing': + if label == 'Stakeholder briefing' or label[0].islower(): continue with self.subTest(label=label): self.assertIn(translation, french) @@ -55,6 +55,29 @@ class ReportPluginTests(unittest.TestCase): source.write_text(json.dumps(report)) self.assertIn('Authored action heading', self.render_text(source, work)) + def test_localised_status_and_severity_badges(self): + catalog = json.loads((ROOT / 'plugins/report/locales.json').read_text()) + labels = [key for key in catalog['fr'] if key[0].islower()] + report = { + 'language': 'fr', 'metadata': {'Author': 'Tester', 'Date': '2026-09-25'}, + 'status': 'paused', 'severity': 'medium', + 'actions': [{'status': key} for key in labels], + 'findings': [{'status': 'confirmed', 'severity': 'high'}], + 'diagnostics': {'hypotheses': [{'status': 'recommended'}]}, + } + with tempfile.TemporaryDirectory() as directory: + work = Path(directory) + source = work / 'input.json' + source.write_text(json.dumps(report)) + rendered = self.render_text(source, work) + for key in labels: + self.assertIn(catalog['fr'][key].upper(), rendered) + for key in ('PENDING', 'RECOMMENDED', 'CONFIRMED', 'HIGH', 'MEDIUM', 'PAUSED'): + self.assertNotIn(key, rendered) + report['actions'] = [{'status': 'statut personnalisé'}] + source.write_text(json.dumps(report)) + self.assertIn('STATUT PERSONNALISÉ', self.render_text(source, work)) + def test_yaml_language_and_invalid_language(self): source_text = (ROOT / 'examples/example-report.yaml').read_text() with tempfile.TemporaryDirectory() as directory: