Skip to content

Add 404 error page and update book configuration#3125

Draft
yl275 wants to merge 1 commit intogoogle:mainfrom
yl275:feat/404-support
Draft

Add 404 error page and update book configuration#3125
yl275 wants to merge 1 commit intogoogle:mainfrom
yl275:feat/404-support

Conversation

@yl275
Copy link

@yl275 yl275 commented Mar 9, 2026

This PR adds a small JavaScript snippet to 404.md, so that when a user visits a broken link under a translated version of the book (for example /es/does-not-exist.html), they are redirected to the corresponding language-specific 404 page (/es/404.html, /zh-CN/404.html, etc.) instead of the English 404.

I tested this, but it seems that 404.md is not going through the translation pipeline.
Am I on the right track with this approach?

fixes #2022

@google-cla
Copy link

google-cla bot commented Mar 9, 2026

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@mgeisler
Copy link
Collaborator

mgeisler commented Mar 9, 2026

I tested this, but it seems that 404.md is not going through the translation pipeline.

I haven't tested this myself, but what you write makes sense: we extract text from the book "chapters", which are the files mentioned in SUMMARY.md. So the 404 is not there, so I would not expect the text to be extracted.

To improve upon this, I think we would need to add code in mdbook-i18n-helpers to detect the input-404 config setting (I hope we have access to the book.toml data there?) and extract the data manually.

We would then also need to test if the page can be translated later...

Am I on the right track with this approach?

Yes, I think this looks like a great approach!

I don't have a lot of time to really test this out right now, but it looks like a nice approach to me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

404 page breaks translations

4 participants