ultrabug / mkdocs-static-i18n

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

Not yet translated files in duplicated navigation entry #300

Open WizzardMaker opened 6 months ago

WizzardMaker commented 6 months ago

I'm currently building a documentation site and stumbled across this bug while migrating my translations. The used docs_structure is folder and I'm using mkdocs-material.

Translation fallback files get sorted in a separate navigation entry with the same name: image

Here, S3/Mana and magic/Test is supposed to be filed with all other entries in S3/Mana and magic/ above.

This is my mkdocs.yml:

site_name: Settlers United Documentation

docs_dir: '../docs/'
extra_css:
  - stylesheets/extra.css

theme:
  favicon: assets/favicon.webp
  logo: assets/favicon.webp
  features:
    - content.tooltips
    - announce.dismiss
    - search.suggest
    - search.highlight
  name: material
  palette:
    scheme: slate
    primary: black
    accent: deep orange

markdown_extensions:
  - attr_list
  - abbr
  - md_in_html
  - tables
  - admonition
  - pymdownx.details
  - pymdownx.highlight:
      anchor_linenums: true
      line_spans: __span
      pygments_lang_class: true
  - pymdownx.inlinehilite
  - pymdownx.snippets
  - pymdownx.superfences
  - pymdownx.tabbed:
      alternate_style: true

plugins:
  - search
  - i18n:
      fallback_to_default: true
      reconfigure_material: true
      reconfigure_search: true
      docs_structure: folder
      languages:
        - locale: en
          default: true
          name: English
          build: true
        - locale: de
          name: Deutsch
          site_name: Settlers United Dokumentation
          build: true

The folder structure is as follows (truncated for only necessary parts)

config/
  mkdocs.yml
docs/
  assets/
  de/
    S3/
      mana-and-magic/
        area-of-effect.md
        basics.md
        cost-progression.md
        table-of-knowledge.md
  en/
    S3/
      mana-and-magic/
        area-of-effect.md
        basics.md
        cost-progression.md
        table-of-knowledge.md
        test.md

I don't know if I configured something wrong with this plugin or if mkdocs-material is breaking something

AngryMane commented 2 months ago

@WizzardMaker (CC: @ultrabug ) This issue was quite easy to reproduce using the provided mkdocs.yaml.

Conclusion

mkdocs-static-i18n needs to modify reconfigure_navigation in folder.py.

Detail

For example, consider the following directory structure:

reconfigure_navigation removes the language info from the path, so the nav is modified as follows:

After this, there is no process to merge the same S3 directories, so nav_item.html in mkdocs-material renders each as a separate item, resulting in the problem you pointed out.

AngryMane commented 2 months ago

@WizzardMaker @ultrabug I think the problem pointed out in this issue will be resolved by the following modifications. https://github.com/ultrabug/mkdocs-static-i18n/compare/main...AngryMane:mkdocs-static-i18n:issue_300

However, I'm aware of another issue where the sidebar display state is reset when transitioning from a page in a non-default language to a page that only exists in the default language(=fallback page).

I don't think this is related to my PR because I can reproduce this problem without my PR, but I think it needs to be fixed. I'll do a little investigation but if I can't find the cause, I will issue a PR for the current fix.