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

Fix/folder with tests #290

Closed kamilkrzyskow closed 7 months ago

kamilkrzyskow commented 8 months ago

For now it's WIP as I couldn't really reproduce the incorrect file lookup in #288 I added tests with WARNING capture, to also handle #277 and with that I found issues concerning Could not find a homepage for locale 'en' in use_directory_urls=False tests.

Sorry it's taking so long @ultrabug the issue is a bit tricky for me, but I hope I'll finish it tomorrow.

EDIT: After further debug process I consider #288 requires a config change by the user, and therefore the PR won't affect it.

kamilkrzyskow commented 8 months ago

I did a bit more debugging with the custom docs and found out that reversed breaks in the nav processing when there is a user defined nav in the docs, because the user defines the nav with paths without the language prefix. However, despite the wrong file being loaded for bot/selfhosting.md for de_CH in the nav processing, the website works fine and everything works as expected ๐Ÿ˜“ As in the navigation link properly resolves the de_CH version of the bot/selfhosting.md file.

Excerpt of the debug.log ```py Nav (C:\MyFiles\PythonVENV\Lib\site-packages\mkdocs\structure\nav.py): input_path=bot/selfhosting.md -- get_file_from_path -- path='bot/selfhosting.md' current en is_relative_to(bot\selfhosting.md, en) -> False default en is_relative_to(bot\selfhosting.md, en) -> False reversed(expected_src_uris): 0 bot\selfhosting.md 1 en\bot\selfhosting.md 2 en\bot\selfhosting.md TreeProcessor (C:\MyFiles\PythonVENV\Lib\site-packages\mkdocs\structure\pages.py): input_path=en/bot/selfhosting.md src_path=en/bot/index.md -- get_file_from_path -- path='en/bot/selfhosting.md' current en is_relative_to(en\bot\selfhosting.md, en) -> True default en is_relative_to(en\bot\selfhosting.md, en) -> True reversed(expected_src_uris): 0 en\bot\selfhosting.md 1 en\en\bot\selfhosting.md 2 en\bot\selfhosting.md 3 bot\selfhosting.md Nav (C:\MyFiles\PythonVENV\Lib\site-packages\mkdocs\structure\nav.py): input_path=bot/selfhosting.md -- get_file_from_path -- path='bot/selfhosting.md' current de_CH is_relative_to(bot\selfhosting.md, de_CH) -> False default en is_relative_to(bot\selfhosting.md, en) -> False reversed(expected_src_uris): 0 bot\selfhosting.md 1 en\bot\selfhosting.md 2 de_CH\bot\selfhosting.md TreeProcessor (C:\MyFiles\PythonVENV\Lib\site-packages\mkdocs\structure\pages.py): input_path=de_CH/bot/selfhosting.md src_path=de_CH/bot/index.md -- get_file_from_path -- path='de_CH/bot/selfhosting.md' current de_CH is_relative_to(de_CH\bot\selfhosting.md, de_CH) -> True default en is_relative_to(de_CH\bot\selfhosting.md, en) -> False reversed(expected_src_uris): 0 de_CH\bot\selfhosting.md 1 en\de_CH\bot\selfhosting.md 2 en\bot\selfhosting.md 3 bot\selfhosting.md TreeProcessor (C:\MyFiles\PythonVENV\Lib\site-packages\mkdocs\structure\pages.py): input_path=de_CH/legal/website.md src_path=de_CH/legal/index.md -- get_file_from_path -- path='de_CH/legal/website.md' current de_CH is_relative_to(de_CH\legal\website.md, de_CH) -> True default en is_relative_to(de_CH\legal\website.md, en) -> False reversed(expected_src_uris): 0 de_CH\legal\website.md 1 en\de_CH\legal\website.md 2 en\legal\website.md 3 legal\website.md ```
kamilkrzyskow commented 8 months ago

The current setup fixes the issues with the file lookup during the nav processing, but I compared the built site with this fix and the previous 1.2.1 commit and both file structures and contents are identical. So I can't figure out what was the issue with https://github.com/ultrabug/mkdocs-static-i18n/issues/288 so I have to wait for more feedback.

kamilkrzyskow commented 8 months ago

Almost took a week ๐Ÿ˜ฎโ€๐Ÿ’จ @ultrabug it's ready for the review. As written before, it turned out there was no issue with the file lookup ๐Ÿ˜“, so the removal of the 1.2.1 release was unnecessary. My confusion in this comment https://github.com/ultrabug/mkdocs-static-i18n/issues/288#issuecomment-1915252000 came from the mixed behaviour as described in https://github.com/ultrabug/mkdocs-static-i18n/pull/290#issuecomment-1922001828 The Navigation and TreeProcessor passed different values to the get_file_from_path function depending on the existence of the nav in the mkdocs.yml file, and it changed the output of the print debug logs I added.

My main error was I didn't check what file actually got returned from the function I just looked at the order of the resolved expected URL list๐Ÿ˜“and actually the correct file was returned. Here are 2 very simple logs of the output (source_path, expected_url_index, returned file), you can see that the new "fixed" log has lower index values than the previous one, so there is an improvement, perhaps it's bigger with docs that use more languages: old_i18n.log new_i18n-fixed.log

Adding the folder structure tests I increased strictness of them too, to detect warnings early, doing that revealed an issue with the use_directory_urls: false setting, which couldn't resolve the homepage for the default language.

So my lacking debug progress escalated a non-issue to a critical one, however the overall trial and error process wasn't pointless or fruitless as in the end I consider the plugin got improved :v:

ultrabug commented 7 months ago

Once again, thank you for your tenacity

kamilkrzyskow commented 7 months ago

@ultrabug Thanks for the merge but when will you release a new version?

ultrabug commented 7 months ago

Once #293 is in I'll release a new version

ultrabug commented 7 months ago

done! 1.2.2 is out!