Edgewall Software

Ticket #300 (closed defect: fixed)

Opened 3 years ago

Last modified 2 years ago

i18n:msg element extracted incorrectly

Reported by: cboos Owned by: palgarvio
Priority: major Milestone: 0.6
Component: Internationalization Version: devel
Keywords: i18n:msg Cc: remy.blank@…

Description

Given the following Genshi i18n:msg element:

<i18n:msg params="date, author">Changed ${dateinfo(change.date)} ago by ${authorinfo(change.author)}</i18n:msg>

the extracted string will be:

#: trac/ticket/templates/ticket.html:224 
#, python-format 
msgid "%(date)s ago by" 
msgstr ""

Not exactly what expected... "Changed" is missing, as well as the expected "%(author)s" second expression.

This can be seen in context in  [T8107].

Tested with advanced-i18n branch, r1028 (r966 tested as well - same extraction). Genshi trunk is not relevant here, as I think it has not the proper support for the i18n:msg element.

Attachments

Change History

  Changed 3 years ago by rblank

  • cc remy.blank@… added

There's another issue with that same changeset  [T8107], when running Trac trunk and the advanced-i18n branch. At the top of every ticket comment, where it says "Changed ... ago by {author}", the space between "by" and the author of the comment is missing.

  Changed 3 years ago by cboos

  • keywords i18n:msg added

  Changed 3 years ago by palgarvio

  • status changed from new to assigned
  • version changed from 0.5.1 to devel

This is not a bug.

In order to properly use i18n:msg from the advanced-i18n branch you have to setup the directives for the template.

>>> from genshi.template import MarkupTemplate
>>> from genshi.filters.i18n import Translator
>>> tmpl = MarkupTemplate("""
... <html xmlns:py="http://genshi.edgewall.org/"
...       xmlns:i18n="http://genshi.edgewall.org/i18n">
...   <span i18n:msg="date, author">
...     Changed ${'10/12/2008'} ago by ${ 'me, the author' }
...   </span>
... </html>""")
>>> translator = Translator()
>>> print list(translator.extract(tmpl.stream))
[(4, None, u'Changed', []), (5, None, u'ago by', [])]
>>>
>>> from genshi.template import MarkupTemplate
>>> from genshi.filters.i18n import Translator
>>> tmpl = MarkupTemplate("""
... <html xmlns:py="http://genshi.edgewall.org/"
...       xmlns:i18n="http://genshi.edgewall.org/i18n">
...   <span i18n:msg="date, author">
...     Changed ${'10/12/2008'} ago by ${ 'me, the author' }
...   </span>
... </html>""")
>>> translator = Translator()
>>> tmpl.add_directives(Translator.NAMESPACE, translator)
>>> print list(translator.extract(tmpl.stream))
[(4, None, u'Changed %(date)s ago by %(author)s', [])]
>>>

Actually the correct way, since setup_i18n will be deprecated is:

>>> tmpl = MarkupTemplate("""
... <html xmlns:py="http://genshi.edgewall.org/"
...       xmlns:i18n="http://genshi.edgewall.org/i18n">
...   <span i18n:msg="date, author">
...     Changed ${'10/12/2008'} ago by ${ 'me, the author' }
...   </span>
... </html>""")
>>> translator = Translator()
>>> translator.setup(tmpl)
>>> print list(translator.extract(tmpl.stream))
[(4, None, u'Changed %(date)s ago by %(author)s', [])]
>>>

Something on on how trac is using this feature is wrong. I'll try to look at trac's code to see what it is because I'm unable to reproduce your results.

  Changed 3 years ago by palgarvio

Actually, sorry, I can reproduce your results. You're not using the directives as attributes, they're "raw" directives.

I'll check them out.

  Changed 3 years ago by palgarvio

  • status changed from assigned to closed
  • resolution set to fixed

Fixed in [1053]. Please confirm and reopen if necessary.

  Changed 3 years ago by cboos

  • status changed from closed to reopened
  • resolution fixed deleted

Thanks for the fix! The extraction is confirmed working in current Trac trunk, using [1055].

The messages.pot now contains:

-#: trac/ticket/templates/ticket.html:224
+#: trac/ticket/templates/ticket.html:227
 #, python-format
-msgid "%(date)s ago by"
+msgid "Changed %(date)s ago by %(author)s"
 msgstr ""

But rendering fails. With the following in the fr_FR catalog:

#: trac/ticket/templates/ticket.html:227
#, python-format
msgid "Changed %(date)s ago by %(author)s"
msgstr "Modifié il y a %(date)s par %(author)s"

I see everything else translated in the ticket page, but the above. And the space is still missing between by and the author name, see comment:1.

  Changed 3 years ago by palgarvio

Ah, dam, forgot about the rendering part :)

  Changed 3 years ago by palgarvio

  • status changed from reopened to closed
  • resolution set to fixed

Complete fix on [1057]. Again, reopen if needed.

  Changed 3 years ago by cboos

Fix confirmed, thanks again!

  Changed 3 years ago by rblank

  • status changed from closed to reopened
  • resolution fixed deleted

There's still an issue with i18n:msg elements. If I have the following snippet in a template:

<p py:if="not info.editable" class="hint" i18n:msg=""><strong>Note:</strong>
  This repository is defined in <code><a href="${href.wiki('TracIni')}">trac.ini</a></code> and cannot be edited on this page.
</p>

then it is rendered as:

<p class="hint"><strong>Note:</strong>
  This repository is defined in <code></code><a href="/wiki/TracIni">trac.ini</a> and cannot be edited on this page.
</p>

Note that the <code> element is rendered before the <a> element, instead of around.

If I remove the i18n:msg="" attribute from the <p> tag, rendering is correct.

  Changed 3 years ago by palgarvio

  • status changed from reopened to closed
  • resolution set to fixed

Fixed in [1059].

follow-up: ↓ 13   Changed 2 years ago by rblank

  • status changed from closed to reopened
  • resolution fixed deleted

There's another occurrence of bad i18n:msg handling on Trac's current trunk. The following snippet (from the roadmap, with a milestone that is late):

<p py:when="milestone.is_late" class="date">
  <i18n:msg params="duration, date">
    <strong>${dateinfo(milestone.due)} late</strong>
    (${format_date(milestone.due)})
  </i18n:msg>
</p>

renders as follows:

<p class="date">
    <strong><a class="timeline" href="/timeline?from=2009-01-01T00%3A00%3A00%2B0100&amp;precision=second" title="2009-01-01T00:00:00+0100 in Timeline">8 months</a> late
    (2009-01-01)
</p>

Note the missing closing tag </strong>.

in reply to: ↑ 12   Changed 2 years ago by cboos

Replying to rblank:

... Note the missing closing tag </strong>.

Remy, are you sure you were using Genshi advanced-i18n at r1059? (or r1060). For me, the tests are passing and I have the </strong> close tag...

Going back to r1058 indeed shows the defect you're describing.

  Changed 2 years ago by anonymous

  • status changed from reopened to closed
  • resolution set to fixed

Dang, I was running r1057, and must have missed those changesets. The strange thing is, everything was working fine up to your latest i18n changes.

Anyway, sorry for the noise.

  Changed 2 years ago by rblank

(anonymous was me)

Add/Change #300 (i18n:msg element extracted incorrectly)

Author


E-mail address and user name can be saved in the Preferences.


Change Properties
<Author field>
Action
as closed
The resolution will be deleted. Next status will be 'reopened'
 
Note: See TracTickets for help on using tickets.