Repository navigation
feat(404): show the not-found page in the reader's language - #2583
Open
NopeCharon wants to merge 1 commit into
Open
NopeCharon wants to merge 1 commit into
NopeCharon wants to merge 1 commit into
Conversation
The site is deployed as static files, so the host serves the same
`404.html` for every missing URL, whatever its language. That page was
hardcoded in English, even though Crowdin already translates the
`error404` strings into every supported language. The strings were
never used. The "Go to Home" button also pointed to `/en`, which drops
readers of translated docs back into English, and the second button
was labelled "Raise a issue".
Build the 404 page from the `error404` UI strings. It still renders in
English. A small inline script that runs right after the content reads
the language prefix of the requested URL (e.g. `/de/guide/missing`).
For a supported language other than English, it swaps in that
language's strings before the first paint. It also updates the `lang`
and `dir` attributes on `<html>` and the document title, and points
"Go to Home" at that language's homepage. English, unprefixed, and
removed-locale URLs keep the English page, which now links to `/`, the
canonical English homepage.
Add an `error404.reportIssue` string ("Report an issue") for the second
button so it can be translated through Crowdin like the rest of the
page. Until it is translated, it falls back to English.
Add Playwright tests covering the English fallbacks and every
translated language.
Signed-off-by: NopeCharon <115794254+NopeCharon@users.noreply.github.com>
✅ Deploy Preview for expressjscom-preview ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
This branch has not been deployed
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 host serves one
404.htmlfor every missing URL, whatever its language, and that page is hardcoded in English. Crowdin already translates theerror404UI strings into every supported language, but nothing uses them. A reader who follows a broken link on/de/…or/ja/…gets an English page. Its Go to Home button points to/en, so it also takes them out of their language. The second button is labelled "Raise a issue".This builds the 404 page from the
error404strings:<html lang>/dirand the document title, and points Go to Home at that language's homepage (e.g./de/)./ru/…) keep the English page. Its home link now goes to/, the canonical English homepage, instead of/en.error404.reportIssuestring ("Report an issue") so the second button can be translated through Crowdin like the rest of the page. Until it is translated, it falls back to English.Only the 404 page content is localized. The surrounding header, sidebar and footer are unchanged.
Validation
tests/e2e/not-found.spec.ts. It covers the English fallbacks (/en/…, unprefixed, removed locale) and all nine translated languages, checking the 404 status,lang, title, heading, message and home link. It passes in Chromium, Firefox and WebKit againstnpm run previewof a production build, and in Chromium and Firefox againstnpm run dev. All 12 cases per browser fail onmain.npm run check,npm run test:unitandnpm run buildpass.