Translate report status and severity badges
Reportist CI A validation or rendering check failed.
Beffroi/reportist/pipeline/head There was a failure building this commit Details

This commit is contained in:
Dandaedre 2026-09-25 11:44:33 +02:00
parent 42edeef51e
commit 9ee41254ed
4 changed files with 88 additions and 10 deletions

View File

@ -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

View File

@ -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"
}
}

View File

@ -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),
)
}

View File

@ -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: