ultrabug / mkdocs-static-i18n

MkDocs i18n plugin using static translation markdown files
https://ultrabug.github.io/mkdocs-static-i18n/
MIT License
236 stars 38 forks source link

[Bug?] 404 page not generated for selected language #284

Open nathancatania opened 11 months ago

nathancatania commented 11 months ago

I have a site with two languages: English and Japanese.

If a user hits the 404 page when the English language is selected (English is the default), the nav and all elements switch to Japanese and the user is left on the Japanese version of the site.

This also occurs with the site for this plugin!

  1. Access the English version of the site: https://ultrabug.github.io/mkdocs-static-i18n/
  2. Click a URL (or edit the URL) that points to a page that doesn't exist, eg: https://ultrabug.github.io/mkdocs-static-i18n/w
  3. The URL will be that of the English site (and the page that doesn't exist), but the site itself will be the French version.

image

  1. Attempting to navigate away from the page results in the user being stuck on the alternative language (i.e: French) and having to use the language switcher to get back.
kamilkrzyskow commented 11 months ago

AFAIK only one 404 page is allowed, as the web server has to load a working file with a proper error message and styling. As for why the 404 page is in French/Japanese is because it's the last language that is built, and therefore overwrites the English (initial) version.

I don't think there is an easy solution to this, because the 404 html source is rendered in another language, so even if there was some kind of working solution to remember the selected language it still wouldn't help in this case 🤔

The only solution I see right now, is to override the 404 page yourself and define your own additional logic on the JavaScript side to render the correct language, which of course I understand, isn't ideal.

ultrabug commented 8 months ago

Same as @kamilkrzyskow this is problem is tied to MkDocs itself and the plugin can't have a generic solution for all themes either...

eXpl0it3r commented 2 months ago

Running into this issue as well with English & French, where French is being used for the 404 page.

Is there are possibility to somehow force the English version? I don't mind the French page getting an English error page, but the other way around is a bit more annoying, as the majority of users will be using the English site.

The only solution I see right now, is to override the 404 page yourself and define your own additional logic on the JavaScript side to render the correct language, which of course I understand, isn't ideal.

Any concrete example on how to achieve this? 😄