Repository navigation
Fix i18n language switching under the /wiki deploy subpath - #8
Merged
Merged
Conversation
On the GitHub Pages project site the wiki is served under /wiki/, but the runtime i18n code assumed the site lives at the domain root: - getLangFromUrl() anchored its regex at the pathname start, so /wiki/fr/ never detected French - translatedUrl() computed wrong targets (/fr/wiki/...), so the language switcher never navigated on translated pages - rewriteNavLinks() wrote bare /fr/... hrefs that 404 under the subpath - the pre-paint head script (base.html) had the same anchored-regex bug - sidenav stripLang() could eat a short content segment matching a 2-3-letter code The runtime now mirrors the established search.js/zone-map.js pattern: read the deploy base from body[data-root] (config.base_url), strip its path part for the site-absolute language math, re-add it to results. The head script strips config.base_url (inlined at build time) before matching; stripLang() now only strips known language codes. Tested via a new Playwright 'subpath' project: tests/setup-subpath.js builds a copy of public/ exactly as the deploy pipeline serves it (rewrite_site_base.py + Pages base_url), served under /wiki/ by tests/serve.js; tests/i18n-subpath.spec.js mirrors the key i18n.spec.js behaviors against it. Full suite: 179 passed, 0 failed.
Sellafield
approved these changes
Oct 15, 2026
Contributor
Author
|
The failing tests are unrelated to the changes made here. I'll fix it in a follow-up PR. |
This was referenced Oct 15, 2026
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.
Problem
On the live site (GitHub Pages project site,
openperpetuum.github.io/wiki/) the language switcher is broken: switching languages never navigates to the translated page, translated pages don't activate their language from the URL, and rewritten nav links 404. Locally (root path) everything works, which is why CI never caught it.Root cause: the runtime i18n code assumed the site lives at the domain root.
getLangFromUrl()anchored its regex at the pathname start →/wiki/fr/...never detected FrenchtranslatedUrl()computed wrong targets (/fr/wiki/...) → returnednull→ no navigationrewriteNavLinks()wrote bare/fr/...hrefs → 404 under the subpathbase.htmlhad the same anchored-regex bug (flash of English, wrong<html lang>)Fix
Mirrors the pattern
search.js/zone-map.jsalready use for runtime URLs: read the deploy base frombody[data-root](config.base_url), strip its path part for the site-absolute language math, re-add it to results. No CI workflow changes needed — the existingsed base_url+rewrite_site_base.pysteps already produce correctdata-rootand static hrefs.tools/gen_i18n.py+ regeneratedstatic/i18n.js: newrootPath()/sitePath()helpers;getLangFromUrl,translatedUrl,rewriteNavLinkswork on site-absolute pathstemplates/base.html: head script stripsconfig.base_url(inlined at build) before matching; sidenavstripLang()now only strips known language codes (window.WIKI_LANGS) instead of any 2–3-char segmentTests
New Playwright
subpathproject that mirrors the deploy exactly:tests/setup-subpath.js: copiespublic/, runs the samerewrite_site_base.pyas CI, pointsdata-root/wikiRootat the Pages URLtests/serve.js: serves the fixture under/wiki/(also normalizes duplicate slashes)tests/i18n-subpath.spec.js: 8 tests — URL language detection, switcher navigation both directions, chrome-only swap on untranslated pages, rewritten nav links (asserts no bare/<lang>/links exist), search under subpath, no-flash head detectionFull suite locally: 179 passed, 0 failed (77 platform skips).