Localise in-article TOC entry text across all 14 languages#2829
Merged
Conversation
…of truth Co-authored-by: pethers <1726836+pethers@users.noreply.github.com>
Copilot created this pull request from a session on behalf of
pethers
May 29, 2026 18:02
View session
Contributor
🏷️ Automatic Labeling SummaryThis PR has been automatically labeled based on the files changed and PR metadata. Applied Labels: testing,refactor,size-l Label Categories
For more information, see |
Contributor
🔍 Lighthouse Performance Audit
📥 Download full Lighthouse report Budget Compliance: Performance budgets enforced via |
Contributor
There was a problem hiding this comment.
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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
scripts/render-lib/section-title-i18n.ts: maps each language-stable canonical section slug → localised journalist title in all 14 languages, exposinglocalizedSectionTitle(slug, lang). Maximises reuse of existing vetted constants rather than duplicating translations:ARTIFACT_TITLE_I18N(risk-assessment,swot-analysis,scenario-analysis, …).per-document-intelligencereuses the reader-guideperDocLabelso both pointers stay in lock-step.what-happened,why-it-matters,key-findings), the coverage appendix, and theDeep Dive: …sections carry explicit vetted 14-language entries.generateArticleTocwiring (article-scannability.ts): resolves each entry vialocalizedSectionTitle(normalizeSlug(e.id), lang)with graceful fallback to the heading text for uncurated sections. English output is byte-identical.tests/section-title-i18n.test.ts(14-language completeness + EN-identity +undefinedfallback) and extended TOC cases intests/article-scannability.test.ts.Design note
Body H2 landmark headings remain English by design:
scripts/validators/article/rules/landmarks.tsrequires English landmarks in the aggregatedarticle.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.Resulting
svTOC:Vad som hände,Riskbedömning,Fördjupning: Korsreferenskarta,Dokumentspecifik underrättelse.