ultrabug / mkdocs-static-i18n

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

Fix/folder file lookup #278

Closed kamilkrzyskow closed 10 months ago

kamilkrzyskow commented 1 year ago

Fixes #277

Fixed the obvious issues, but when I wanted to delete this additional fallback path it creates warnings for missing nav files:

        # default language path detection
        if self.plugin.config.fallback_to_default is True:
            expected_src_uris.append(PurePath(self.plugin.default_language) / expected_src_uri)
INFO    -  The following pages exist in the docs directory, but are not included in the "nav" configuration:
             - en\api\index.md
             - en\bot\faq.md
             - en\legal\api.md
             - en\legal\bot.md
             - en\legal\website.md
WARNING -  A relative path to 'api/index.md' is included in the 'nav' configuration, which is not found in the documentation files.
WARNING -  A relative path to 'bot/faq.md' is included in the 'nav' configuration, which is not found in the documentation files.
WARNING -  A relative path to 'legal/bot.md' is included in the 'nav' configuration, which is not found in the documentation files.
WARNING -  A relative path to 'legal/api.md' is included in the 'nav' configuration, which is not found in the documentation files.
WARNING -  A relative path to 'legal/website.md' is included in the 'nav' configuration, which is not found in the documentation files.

So I kept it around, and therefore it still generates an invalid path sometimes:

de-CH/legal/bot.md
en/de-CH/legal/bot.md
en/legal/bot.md
legal/bot.md

I don't know what would be a good solution, to avoid any warnings and avoid such default/current/.../file.md paths, but for now it's enough to patch it.

kamilkrzyskow commented 1 year ago

Uh oh o_O, the commits got duplicated?

kamilkrzyskow commented 1 year ago

I had to fetch the current main branch and cherry-pick the commits, because the hash of c41bb168232eea3c9d37c4b7841794ecec4c70f2 and 037001a30161a6acc80303855a14084aca051eb9 changed after the PR, because you rebased (?) on your local PC and then pushed to upstream? Dark magic of git, I guess. It's best to just merge via the GitHub interface :v:

Andre601 commented 1 year ago

Installed this PR using pip install git+https://github.com/kamilkrzyskow/i18n.git@fix/folder-file-lookup and used it on my docs (The ones I encountered this issue with outlined in #277).

The logs don't show any errors and the links seem to be properly translated now to the right page, as can be seen at the bottom of the logs here, where I navigated to the page using the embedded links on the index page.

$ mkdocs serve
INFO    -  Building documentation...
INFO    -  theme_overrides_manager: Theme overrides manager initialized
INFO    -  mkdocs_static_i18n: Building 'en' documentation to directory: C:\Users\*******\AppData\Local\Temp\mkdocs_ia8jef9_
INFO    -  Cleaning site directory
INFO    -  language_flags: Registered processors
INFO    -  theme_overrides_manager: Backing up 1 file...
INFO    -  theme_overrides_manager: Restoring 1 file...
INFO    -  theme_overrides_manager: Theme overrides manager initialized
INFO    -  mkdocs_static_i18n: Building 'de-CH' documentation to directory: C:\Users\*******\AppData\Local\Temp\mkdocs_ia8jef9_\de-CH
INFO    -  mkdocs_static_i18n: Language 'de-CH' is not supported by lunr.js, not setting it in the 'plugins.search.lang' option
INFO    -  mkdocs_static_i18n: Overriding 'de-CH' config 'copyright' with 'Dokumentation mit
<img alt="\u2764" class="twemoji heart-anim md-footer-custom-text" src="https://twemoji.maxcdn.com/v/latest/svg/2764.svg" title="Liebe">
gemacht und unter der
<a href="https://github.com/purrbot-site/Docs/blob/master/LICENSE" target="_blank" rel="nofollow">MIT-Lizenz</a> verf▒gbar.
'
INFO    -  mkdocs_static_i18n: Updating 'de-CH' config 'extra' with '{'translate': {'missing_translation': 'Diese Seite wurde noch nicht ▒bersetzt.', 'not_translatable': 'Diese Seite kann nicht ▒bersetzt werden und ist darum nur auf Englisch verf▒gbar.', 'footer': 'Erstellt mit <a href="https://www.mkdocs.org" target="_blank" rel="noopener">MkDocs</a>,\n<a href="https://squidfunk.github.io/mkdocs-material" target="_blank" rel="noopener">Material for MkDocs</a> und\n<a href="https://facelessuser.github.io/pymdown-extensions/" target="_blank" rel="noopener">Pymdown Extensions</a>.\n'}}'
INFO    -  mkdocs_static_i18n: Overriding 'de-CH' config 'site_description' with 'API-Dokumentation und Wiki von *Purr*'
INFO    -  mkdocs_static_i18n: Overriding 'de-CH' config 'site_name' with 'PurrBot Dokumentation'
INFO    -  mkdocs_static_i18n: Translated 4 navigation elements to 'de-CH'
INFO    -  language_flags: Registered processors
INFO    -  theme_overrides_manager: Backing up 1 file...
INFO    -  theme_overrides_manager: Restoring 1 file...
INFO    -  Documentation built in 4.52 seconds
INFO    -  [14:40:05] Watching paths for changes: 'docs', 'mkdocs.yml', 'theme'
INFO    -  [14:40:05] Serving on http://127.0.0.1:8000/
INFO    -  [14:40:16] Browser connected: http://127.0.0.1:8000/
INFO    -  [14:41:13] Browser connected: http://127.0.0.1:8000/de-CH/
INFO    -  [14:41:15] Browser connected: http://127.0.0.1:8000/de-CH/api/
INFO    -  [14:41:18] Browser connected: http://127.0.0.1:8000/de-CH/legal/
INFO    -  [14:41:28] Browser connected: http://127.0.0.1:8000/de-CH/legal/bot/

So this fix seems to work. :thumbsup:

ultrabug commented 1 year ago

I've not yet looked at this since I said I was going to work on the blog plugin support first.

I've been struggling with how the plugin detects translated files when they've been generated (like the blog do) so I've decided to switch from basing the detection logic from dest_uri to src_uri in #279

I'd thus like #279 to be merged first, then get this PR reviewed and merged. Get a release on the road, and get back to work on the blog support.

Hope that's okay?

If you could give #279 a try, that would be great to confirm that I'm not breaking anything!

kamilkrzyskow commented 1 year ago

I won't have access to a PC to test it today so perhaps @Andre601 could check out that other branch

ultrabug commented 10 months ago

Thanks @kamilkrzyskow I'll make a release with that