collective / i18ndude

i18ndude performs various tasks related to ZPT's, Python Scripts and i18n.
https://pypi.org/project/i18ndude
4 stars 9 forks source link

Handle dynamic content (with tags) within a translation #110

Open gforcada opened 1 year ago

gforcada commented 1 year ago

The simple case, where a string has some dynamic data is already supported, e.g:

<span i18n:translate=''>
  <span tal:replace='context.name' i18n:name='name' /> was born in
  <span tal:replace='context.country_of_birth' i18n:name='country' />.
</span>

From Chameleon docs

But what about:

<span i18n:translate="">
The Oscar for
<span class="some formatting">${view/type}</span>
goes to
<spn class="some other formatting">${view/winner}</span>
!!
</span>

AFAIK there is no solution but to break the sentence into three:

The Oscar for, goes to and !!.

The problem is that not all languages have the same constructs, so being able to move around the structure is actually needed 😕

Is there any alternative? 🤔 🍀

ale-rt commented 1 year ago

I did not quite understand the question, but it seems to me you can do:

<span i18n:translate="">
  The Oscar for
  <span class="some formatting"><tal:i18n i18n:name="type">${view/type}</tal:i18n></span>
  goes to
  <span class="some other formatting"><tal:i18n i18n:name="name">${view/winner}</tal:i18n></span>!!
</span>
mauritsvanrees commented 1 year ago

First, I would add a message id, otherwise you will lose translations if you add another class. So i18n:translate="msg_oscar". If you then add a class, the translation is only marked as fuzzy, so translators know they need to have another look at it.

Second, what Alessandro says, works, but it leads to this in a German po file (that was the easiest for me to check):

#. Default: "The Oscar for <span class=\"some formatting\">${type}</span> goes to <span class=\"some other formatting\">${name}</span>!!"
#: ../browser/templates/skill.pt
msgid "msg_oscar"
msgstr "Der Oscar für <span class=\"some formatting\">${type}</span> ist für <span class=\"some other formatting\">${name}</span>!!"

I would simplify it to this:

<span i18n:translate="msg_oscar">
  The Oscar for
  <span i18n:name="type" class="some new formatting">${context/portal_type}</span>
  goes to
  <span i18n:name="name" class="some other formatting">${context/Title}</span>!!
</span>

(I used context/portal_type and Title so it works for me in a randomly chosen template.) Result in po:

#. Default: "The Oscar for ${type} goes to ${name}!!"
#: ../browser/templates/skill.pt
msgid "msg_oscar"
msgstr "Der Oscar für ${type} ist für ${name}!!"

Now you can add or changes classes all you want, or even change a span to h2 and no translations need to change.

gforcada commented 1 year ago

Thanks, seems that I did not find the right combination. As soon as I see that template again I will give it a try 😄