Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Both languages show on the left-side menu instead of the current language's content only #289

Closed
ztheory opened this issue Jan 30, 2024 · 5 comments

Comments

@ztheory
Copy link

ztheory commented Jan 30, 2024

Hello,

Firstly, thank you for maintaining this project.

Running mkdocs-material 9.4.7 with mkdocs-static-i18n 1.2.0.

I am probably missing something simple, but I cannot figure it out.

When running mkdocs serve, I get the following warning, even though I have an index.md file in my /fr/ folder. Perhaps related to the second issue.

INFO    -  mkdocs_static_i18n: Building 'fr' documentation to directory: /tmp/mkdocs_8oc6466d/fr
WARNING -  mkdocs_static_i18n: Could not find a homepage for locale 'fr'

In addition, on the left menu, all of the content shows for both English and French, even when being in my /fr/ or /en/ version of the documentation.

Appreciate any advice in advance.

site_name: Quad9 Documentation
site_url: https://quad9dns.github.io/documentation/en
  #repo_url: https://github.com/Quad9DNS/documentation

plugins:
  - social:
      cards_layout_options:
        background_color: "#2E303E"
  - search
  - i18n:
      reconfigure_material: true
      fallback_to_default: false
      docs_structure: suffix
      languages:
        - locale: en
          default: true
          name: English
          build: true
        - locale: fr
          name: Français
          build: true
markdown_extensions:
  - admonition
  - attr_list
  - md_in_html
  - pymdownx.inlinehilite
  - pymdownx.snippets
  - pymdownx.superfences
  - pymdownx.emoji:
      emoji_index: !!python/name:materialx.emoji.twemoji
      emoji_generator: !!python/name:materialx.emoji.to_svg
  - pymdownx.tabbed:
     alternate_style: true

extra_css:
  - stylesheets/extra.css

theme:
  name: material
  favicon: images/favicon.svg
  logo: assets/logo_light.svg
  font: false
  features:
    - navigation.index
    - navigation.sections
      #    - navigation.instant
    - toc.integrate
    - content.code.copy
    - header.autohide
  language: en
  palette:
    - scheme: slate
      toggle:
        icon: material/brightness-7
        name: Switch to Light Mode
      primary: pink
      accent: pink
    - scheme: default
      toggle:
        icon: material/brightness-4
        name: Switch to Dark Mode
      primary: pink
      accent: pink

extra:
  alternate:
    - name: English
      link: /documentation/en/ 
      lang: en
    - name: Français
      link: /documentation/fr/
      lang: fr

image

@kamilkrzyskow
Copy link
Contributor

kamilkrzyskow commented Jan 30, 2024

Hello @ztheory,
your configuration has docs_structure: suffix yet you mention you're using different directory paths for en/ and fr/.
As per the documentation https://ultrabug.github.io/mkdocs-static-i18n/setup/choosing-the-structure/#the-suffix-structure
suffix files should be siblings in the same directory.

@ztheory
Copy link
Author

ztheory commented Jan 30, 2024

Hello @kamilkrzyskow

Ugh. Sorry about that. I was modifying this file endlessly and must have overwritten the folder option which I set previously.

One more question, if I may. Sorry for these silly issues.

When I select French, it results in a 404, even though I have an index.md file. Do I need specify the index file manually?

When I select French, then select English again, it goes to an unexpected page instead of the English index.md file.

$ ls docs/fr/ | grep .md
FAQ.md
FAQs.md
index.md
services.md
$ ls docs/en/ | grep .md
FAQs.md
index.md
services.md

image

image

@kamilkrzyskow
Copy link
Contributor

kamilkrzyskow commented Jan 30, 2024

When I select French, it results in a 404, even though I have an index.md file. Do I need specify the index file manually?

I believe this issue stems from site_url: https://quad9dns.github.io/documentation/en I expect the generated French link is then https://quad9dns.github.io/documentation/en/fr/

So try changing the site_url to https://quad9dns.github.io/documentation/

When I select French, then select English again, it goes to an unexpected page instead of the English index.md file.

As for this, I'm not sure, the 404.html page isn't really a page but a template, so perhaps the underlying code somehow caches / doesn't clear data from a previous processed page, which leads to using this other data instead to create the selector on the 404 page. It would have to be explicitly programmed for it to go back to the root index 🤔

Also keep in mind that only one 404.html is being handled by the server (at least in this static page setting / GitHub pages)
#284 so it will always be corresponding to the last generated language.

@kamilkrzyskow
Copy link
Contributor

kamilkrzyskow commented Jan 30, 2024

Actually wait, you're using both reconfigure_material: true together with your own extra: alternate:, so it's hard for me to pinpoint where is the issue. Please debug it a bit more with different paths and write out what does the language selector point to.
Access each page:

  • 127.0.0.1:8000/documentation/ - expected 404
  • 127.0.0.1:8000/documentation/en/
  • 127.0.0.1:8000/documentation/en/fr/
  • 127.0.0.1:8000/documentation/fr/ - expected 404
    and then check each link in the selector. The issue with French gotta be some wrongly connected url.

EDIT:
I think, I'm starting to understand the issue a bit. You're trying to have English at en/ prefix and French at fr/ prefix.
From mkdocs-static-i18n==1.0.0 the language-code/ prefix path for the default language stopped being generated, and there is only the default page at root / and language-code/ prefix for other languages like fr/. The rationale behind it was to avoid duplicates and have a cleaner sitemap.xml.
https://ultrabug.github.io/mkdocs-static-i18n/sitemap.xml

@ztheory
Copy link
Author

ztheory commented Mar 9, 2024

Hello @kamilkrzyskow

Terribly sorry for the late reply.

Correct, I had to change the path before publishing. I got everything working perfectly. Thank you so very much.

@ztheory ztheory closed this as completed Mar 9, 2024
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

No branches or pull requests

2 participants