ultrabug / mkdocs-static-i18n

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

[Question] Can you hide/supress link warnings by mkdocs for non-existing files? #277

Closed Andre601 closed 8 months ago

Andre601 commented 11 months ago

My docs have pages that cannot be translated for various reasons, so the translations obviously don't have the files present. This however causes MkDocs to report links in other files pointing to these ones. I talk about this warning in particular:

WARNING -  Doc file 'de-CH/legal/index.md' contains a relative link 'bot.md', but the target 'de-CH/legal/bot.md' is not found among documentation files.

Is there a way in the plugin to have these links be ignored? The plugin is configured to build the default lang file as a replacement, so the file itself would exist, but this check seems to happen before the build?

Andre601 commented 11 months ago

Actually, it seems that this also causes an issue with linking, because the link [bot](bot.md) leads to a 404 page on the built docs, because MkDocs isn't parsing the link into the actual page.

Like, I have the following file structure:

docs/
├── de-CH/
│   └── legal/
│       └── index.md
└── en/
    └── legal/
        ├── bot.md
        └── index.md

With index.md having a link to bot.md in both folders. For the default language (English) does this work fine, but for de-CH does it give a 404 because it doesn't have a bot.md file present and MkDocs treats it as a broken link, not parsing it...

Can this be fixed?

kamilkrzyskow commented 11 months ago

Weird, I have a lot of untranslated pages and don't have this error.

But from your docs tree example I see you're using the folder structure instead of suffix like I do.

Perhaps the bug is somewhere there in the folder structure logic. I will try to reproduce it based on the example.

Andre601 commented 11 months ago

The actual docs source can be found here: https://github.com/purrbot-site/Docs

kamilkrzyskow commented 11 months ago

I did some debugging and it turned out there are actually two bugs in the folder file lookup: Here is a console output of some print statements:

looked up target -> de-CH/credits/index.md
variant=credits/index.md file=None
variant=en/de-CH/credits/index.md file=None
variant=de-CH/credits/index.md file=File(src_uri='de-CH/credits/index.md', dest_uri='de-CH/credits/index.html', name='index', url='de-CH/credits/')
---
looked up target -> de-CH/legal/bot.md
variant=legal/bot.md file=None
variant=en/de-CH/legal/bot.md file=None
variant=de-CH/legal/bot.md file=None
WARNING -  Doc file 'de-CH/legal/index.md' contains a relative link 'bot.md', but the target 'de-CH/legal/bot.md' is not found among documentation
           files.
---
looked up target -> de-CH/legal/api.md
variant=legal/api.md file=None
variant=en/de-CH/legal/api.md file=None
variant=de-CH/legal/api.md file=None
WARNING -  Doc file 'de-CH/legal/index.md' contains a relative link 'api.md', but the target 'de-CH/legal/api.md' is not found among documentation
           files.

Taking the issue from the OP, the de-CH/legal/bot.md file lookup searches for en/de-CH/legal/api.md instead of en/legal/api.md and therefore it can't find such file.

As for the second bug, it's in the lookup order of the variants. For example if we'd fix the first issue, for de-CH/credits/index.md it would lookup en/credits/index.md before finding de-CH/credits/index.md.

Andre601 commented 11 months ago

Not sure if this is the right logic you have there...

I have en set as default, so the effective path for the link should be equivalent to api.md as an example.

Tho, Ialso may misunderstand stuff...

kamilkrzyskow commented 11 months ago

Maybe I missed something when testing, as I was mostly focused on fixing the broken path and warning. Then found the wrong order of alternative path lookup.

You can clone the branch from the PR and make a more thorough review to make sure nothing else was broken in the process.

Andre601 commented 11 months ago

Maybe I missed something when testing, as I was mostly focused on fixing the broken path and warning. Then found the wrong order of alternative path lookup.

You can clone the branch from the PR and make a more thorough review to make sure nothing else was broken in the process.

Yeah. I'll try to install it with pip and see if there's anything... Will report it in the PR in such a case.