Search code examples
internationalizationgithub-pagesmkdocsmkdocs-material

Changing translation on GitHub page homepage with mkdocs-static-i18n results in a 404


So I have built a website using GitHub Pages and mkdocs. I'm using mkdocs-static-i18n to deploy a translation (in French). Everything works great except on the main page (the one built from index.md). If I try to change the language on that page, I get a 404. Any idea what the issue might be? I'm using the folder version of static-i18n. Here's the relevant code with site name obscured:

- i18n:
      docs_structure: folder
      default_language: en
      languages:
        - locale: en
          default: true
          name: English
          build: true
          site_name: My website
          site_description: My description
        - locale: fr
          name: Français
          build: true
          site_name: French name
          site_description: French description
          nav_translations:
            My stuff
extra:
  alternate:
    # Switch to English
    - name: English
      link: /en/
      lang: en

    # Switch to French
    - name: Français
      link: /fr/
      lang: fr

I tried changing the name of index.md to homepage to avoid this issue, but I get the same problem and the base link doesn't redirect properly to my homepage.

Edit: I have noticed clicking on the translation shortens my URL. For instance, if the homepage is something.github.io/some-page, it turns into something.github.io/fr instead of something.github.io/some-page/fr. I assume this is the problem.


Solution

  • Apparently the issue was related to the alternate portion of the config. In case this is helpful to anyone, here's what I changed to make it work:

    extra:
      alternate:
        # Switch to English
        - name: English
          link: ""
          lang: en
    
        # Switch to French
        - name: Français
          link: fr
          lang: fr