squidfunk / mkdocs-material

Documentation that simply works
https://squidfunk.github.io/mkdocs-material/
MIT License
21.2k stars 3.57k forks source link

404.html redirects to a different language #7728

Closed mgriff88 closed 1 week ago

mgriff88 commented 1 week ago

Description

Some background: Our docs site is available in English and Japanese. Our URL pattern looks like this: English: https://www.example.com/about/ Japanese: https://www.example.com/ja/about/ So, the English site does not use /en/ in the URL itself, as it is the default language.

image

For some reason, when accessing any broken link, the 404 page changes the entire site's language preference over to Japanese. See the attachment: it changes the Title, HTML Lang, etc. Then, if you click Home or whatever from there, it brings you to the Japanese home. Even if you were reading the site in English from the start. This forces you to reset your language back to English. Same issue happens when using a custom override of the 404.html template.

Any idea why this might be happening and how to prevent it? Or better yet, any idea how to have separate English and Japanese 404 pages? Since it's not a Markdown file and it's just coming from 404.html, I'm not seeing how to do that.

Here is some of the relevant setup in my mkdocs.yml in case it helps:

theme:
  name: material
  custom_dir: overrides
...
  language: en
...
plugins:
  - i18n:
      docs_structure: folder
      languages:
        - locale: en
          default: true
          name: English
          build: true
        - locale: ja
          name: Japanese
          build: true
          site_name: "ドキュメント"
...
extra:
  alternate:
    - name: English
      link: / 
      lang: en
    - name: 日本語
      link: /ja/
      lang: ja

Related links

Proposed change

No response

Before submitting