ultrabug / mkdocs-static-i18n

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

Relative html img links are referencing non existing locale files since v1 #275

Closed machinaeXlasse closed 8 months ago

machinaeXlasse commented 8 months ago

If I define a link to an img in my documentation and use markdown style

![screenshot](./assets/live_toggle.png)

The image path will be adapted to always find the non localized image in either language file

If I define a link to an img and use html

<img src="./assets/live_overview.png" alt="screenshot"/>

The image path will only work for the default language since the relative path is kept intact and will not find anything at .../fr/assets/live_overview.png

I understand that there have been changes to improve efficiency for non locale assets as described in #252

Though I would expect that html (img) links are treated similar to markdown image tags and are being converted.

Maybe I am just missing something.

I use mkdocs_static_i18n-1.1.1
with mkdocs-1.5.3
and mkdocs_material-9.4.6

Thanks a lot for your beautiful work!

machinaeXlasse commented 8 months ago

Issue has been fixed with v1.2.0

Sorry for the hassle, probably could have seen it coming with the pending pull request. Thank you!

kamilkrzyskow commented 8 months ago

Actually version 1.2.0 didn't add anything after 1.1.1 that would influence this behavior.

Also I don't think MkDocs processes the links of images written in HTML instead of Markdown, but as you say it's fixed, then perhaps some other version fixed that and you haven't used it before 🤔

machinaeXlasse commented 8 months ago

Uh, I'm sorry the problem is not fixed actually. I was looking at the wrong part of the docs .

So am I right that, since images (files) are not moved to the language dir anymore, html links will "break" because they are not processed?

Do you have an idea how to deal with this? Since html has more features in how images are displayed it is the favored choice in some places.

kamilkrzyskow commented 8 months ago

If I understand correctly the image name and extension doesn't change, just the relative path of directories to it. As mentioned in this comment (https://github.com/ultrabug/mkdocs-static-i18n/pull/256#issuecomment-1712484289) you could use absolute paths, but as I point out in the comment below (https://github.com/ultrabug/mkdocs-static-i18n/pull/256#issuecomment-1714816686), you need to keep in mind the real base path, as it might be /repository-name/ instead of just /. Also in the case you change the name of the base path you would have to modify every link ✌️

Since html has more features in how images are displayed it is the favoured choice in some places.

What other features do you have in mind? You can add CSS classes or other attributes with the attr_list extension to display the images in a different way. https://python-markdown.github.io/extensions/attr_list/

markdown_extensions:
  - attr_list
![screenshot](assets/live_toggle.png){ style='width: 50%;' }
machinaeXlasse commented 8 months ago

I see, thanks for the clarification!

The attribute list hint is great! Didn't come to my mind even though we already used the extension for another purpose. I will have a go with it. Some 200 html tags need to be replaced but then the style is also more consistent. I may not forget to add this in the docs contibution guidelines 😉

You can add CSS classes or other attributes with the attr_list extension to display the images in a different way. https://python-markdown.github.io/extensions/attr_list/

Serves as a very good solution for me.

I will leave a note that, without knowing anything about the underlying process, I would love relative links in html tags to be working with multiple language directories.