Skip to content

Localise in-article TOC entry text across all 14 languages#2829

Merged
pethers merged 1 commit into
mainfrom
copilot/improve-localisation-news-article-html
May 29, 2026
Merged

Localise in-article TOC entry text across all 14 languages#2829
pethers merged 1 commit into
mainfrom
copilot/improve-localisation-news-article-html

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 29, 2026

The generated in-article Table of Contents rendered its entry text from the English body H2 headings, so non-English articles (e.g. …-sv.html, …-fr.html) showed an all-English TOC ("What Happened", "Risk Assessment", "Deep Dive: …") despite localised chrome around it.

Changes

  • New single source of truth — scripts/render-lib/section-title-i18n.ts: maps each language-stable canonical section slug → localised journalist title in all 14 languages, exposing localizedSectionTitle(slug, lang). Maximises reuse of existing vetted constants rather than duplicating translations:
    • Sections whose label equals the backing artifact title delegate to ARTIFACT_TITLE_I18N (risk-assessment, swot-analysis, scenario-analysis, …).
    • per-document-intelligence reuses the reader-guide perDocLabel so both pointers stay in lock-step.
    • Journalist-framed labels (what-happened, why-it-matters, key-findings), the coverage appendix, and the Deep Dive: … sections carry explicit vetted 14-language entries.
  • generateArticleToc wiring (article-scannability.ts): resolves each entry via localizedSectionTitle(normalizeSlug(e.id), lang) with graceful fallback to the heading text for uncurated sections. English output is byte-identical.
  • Tests: tests/section-title-i18n.test.ts (14-language completeness + EN-identity + undefined fallback) and extended TOC cases in tests/article-scannability.test.ts.

Design note

Body H2 landmark headings remain English by design: scripts/validators/article/rules/landmarks.ts requires English landmarks in the aggregated article.md, and the analysis body content is English-only across languages. The TOC is navigation chrome, so it is the correct (and validator-safe) place to localise.

// article-scannability.ts — generateArticleToc
const localized = localizedSectionTitle(normalizeSlug(e.id), lang);
const text = localized ?? e.text; // EN unchanged; uncurated → heading text

Resulting sv TOC: Vad som hände, Riskbedömning, Fördjupning: Korsreferenskarta, Dokumentspecifik underrättelse.

…of truth

Co-authored-by: pethers <1726836+pethers@users.noreply.github.com>
@pethers pethers marked this pull request as ready for review May 29, 2026 18:02
Copilot AI review requested due to automatic review settings May 29, 2026 18:02
@github-actions github-actions Bot added testing Test coverage refactor Code refactoring size-l Large change (250-1000 lines) labels May 29, 2026
@github-actions
Copy link
Copy Markdown
Contributor

🏷️ Automatic Labeling Summary

This PR has been automatically labeled based on the files changed and PR metadata.

Applied Labels: testing,refactor,size-l

Label Categories

  • 🗳️ Content: news, dashboard, visualization, intelligence
  • 💻 Technology: html-css, javascript, workflow, security
  • 📊 Data: cia-data, riksdag-data, data-pipeline, schema
  • 🌍 I18n: i18n, translation, rtl
  • 🔒 ISMS: isms, iso-27001, nist-csf, cis-controls
  • 🏗️ Infrastructure: ci-cd, deployment, performance, monitoring
  • 🔄 Quality: testing, accessibility, documentation, refactor
  • 🤖 AI: agent, skill, agentic-workflow

For more information, see .github/labeler.yml.

@github-actions
Copy link
Copy Markdown
Contributor

🔍 Lighthouse Performance Audit

Category Score Status
Performance 85/100 🟡
Accessibility 95/100 🟢
Best Practices 90/100 🟢
SEO 95/100 🟢

📥 Download full Lighthouse report

Budget Compliance: Performance budgets enforced via budget.json

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR localizes the in-article Table of Contents (TOC) entry text across all 14 supported languages by mapping language-stable section slugs (derived from <h2 id="...">) to translated journalist-facing titles, while intentionally keeping the body landmark headings in English.

Changes:

  • Added a single source of truth (localizedSectionTitle(slug, lang)) to resolve localized TOC labels, delegating to existing vetted i18n tables where possible.
  • Updated TOC generation to use slug-based localization with a safe fallback to the original heading text for uncurated sections.
  • Added/extended Vitest coverage to validate 14-language completeness, English byte-identity, delegation reuse, and fallback behavior.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
scripts/render-lib/section-title-i18n.ts Introduces canonical slug → localized TOC title resolution, reusing existing i18n sources for artifact titles and reader-guide chrome.
scripts/render-lib/article-scannability.ts Wires TOC rendering to use localized section titles by normalized section id, with fallback to heading text.
tests/section-title-i18n.test.ts Adds direct unit tests for slug coverage across all languages, English identity, and undefined fallback.
tests/article-scannability.test.ts Adds end-to-end TOC output tests validating localization, English identity, per-document label reuse, and fallback behavior.

@pethers pethers merged commit 04352e8 into main May 29, 2026
18 checks passed
@pethers pethers deleted the copilot/improve-localisation-news-article-html branch May 29, 2026 18:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

refactor Code refactoring size-l Large change (250-1000 lines) testing Test coverage

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants