-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: adapt image refuri if image uri has been adapten by i18n #12849
base: master
Are you sure you want to change the base?
feat: adapt image refuri if image uri has been adapten by i18n #12849
Conversation
Hi @koeppe-at-pdtec - thank you for the bugreport and repro zipfile. A note: I don't think that this relates to the To help me understand, could you summarize what happens when you build an affected project, and what you expected to happen? |
Hi @jayaddison, thanks for response. Here es a more detailed explanation . In case you have a figure:: directive and use the :target: option, the behavior when building it with the html builder is, the image in the document becomes linked to the target. If sphinx-intl is used to handle a multilanguage document it does provide handling language specific image files. Maybe i have a misunderstanding at this point. I was thinking spinx-intl is the part handling all language specific stuff, but you are right, it is not part of the config. On the other hand some of the extensions a loaded by defautl, so i was not sure. There is a configurable mapping, where image.png is transformed to image.de.png in case the language is set to e.g., 'de'. If there is an image named image.de.png it will rewrite the reference in the rst to point to image.de.png otherwise it keeps going wit image.png. This allows to have language specific figures. If you use the :target: to point to a url or a file it currently is ignored by the option to have language specific targets. Here comes the issue: There are mutlitple options to handle those cases.
You can reproduce the issue by building my example like described and klick on the images in the english version, they work as expected. The same klick wil point to a nonexisting file in th german version though. Let me know if this helps to understand the Issue. |
Ok, I understand that clicking the image doesn't work in the DE version. A next question is: before clicking, does the image load correctly in both EN and DE? (in other words: is the HTML |
Hi @jayaddison, yes the images are displayed correctly for de and en version. This works perfectly fine. |
Ok, thank you. Apologies for being slow/repetitive, but I'm trying to think through the problem. When a figure is included in HTML output, if it has the In this particular case, the In the general case, the target may be a different object than the image -- it could be an internal or an external (different domain) URL. At some stage during the build, because Does that seem correct @koeppe-at-pdtec? |
Hi @jayaddison , that exactly describes the issue. No worries about asking back. I think this issue is not that obvious an as i'm not a native englich speaker may lack clearity :) Not updating the a href is the problem. |
What would the effect(s) of that be for translation teams? Would they be editing the relevan image URL(s) in each case, typically only to adjust the language code? |
In case you have separated files for different languages the translator need to adapt the language codes. So it would be kind of a misuse of the PO file here, but i think it is at least the most clear and unintrusive way to handle this.
|
I'm not too keen on the per-language-target-option approach, because it implies that updating that part of a translated copy of the original work would require updating the original work itself. |
Would adding support for a |
If i understand correctly, this is close to the fix i proposed in my MR. For my specific use-case this probably would be a fix. But I can see other users that have the need to point to language specific url's, e.g. pointing to the englisch or german version of a wikipedia page. For those users the solution might not fullfill their requirements. And i can also see in our case this might be a thing in the future. They probalby would get their requirement solved using the po files to handle this. Means, if there is a 'translation' of the target specified, take this, otherwise kepp going with the default language. Like handling untranslated text. Or maybe we need a totally different approach, but i currently have not any good idea. Just to be clear, i'm pleased with any kind of solutiuon, as i lack deep insight to sphinx, i can not judge what is the better solution. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I more-or-less agree that this feature is reasonable. A few things that I think would help:
- Filing a feature request that describes this could be useful; generally that's a good way to record and confirm the details of a bug/feature request before accepting an implementation. Exceptions are possible, including for small changes, but I think this change could be nontrivial.
- Test coverage would be useful to demonstrate what the change is intended to do (and perhaps to confirm/test some things that it should not do).
- I think that the other branch of the
if
condition here (imguri.endswith(os.extsep + '*')
) might need to be handled here. If so, test coverage could again help - if not, it may be helpful to explain why it isn't needed.
Ah, and an optional extra idea: if we do add a localized version of a hyperlink -- whether automatically by replacement, or using |
Hi @jayaddison ok i'll create a feature request. I'll notify you when i made progress or get stuck. |
Sounds good, thank you @koeppe-at-pdtec 👍 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems reasonable @koeppe-at-pdtec. It should have a CHANGES entry and ideally tests.
A
Converted to draft until i have time to fix it and provide the unittests i offered above. |
Subject: adapt image refuri if image uri has been adapten by i18n
Hello Dev-Team, i stumbled accross an issue, when using sphinx-intl and image references in figures.
Here is a solution that solves the problem for me. Maybe you like to include it to Sphinx.
Greets
Alex
Feature or Bugfix
Purpose
figure_language_filename = "{root}.{language}{ext}"
reference uri's defined via :target: declaration in figures are broken.Example:
For language de ./cherry.png is replaced by cherry.de.png if the image is found in the source dir.
When HTML is built the file cherry.de.png is stored in _images but not cherry.png.
So the reference gets broken for alle language specific images.
In my case i like to link to the corresponding translated image also in the reference.
Detail
Example
source.zip