Edgewall Software

Opened 15 years ago

Closed 15 years ago

Last modified 15 years ago

#300 closed defect (fixed)

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.

Change History (15)

comment:1 Changed 15 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.

comment:2 Changed 15 years ago by cboos

  • Keywords i18n:msg added

comment:3 Changed 15 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.

comment:4 Changed 15 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.

comment:5 Changed 15 years ago by palgarvio

  • Resolution set to fixed
  • Status changed from assigned to closed

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

comment:6 Changed 15 years ago by cboos

  • Resolution fixed deleted
  • Status changed from closed to reopened

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.

comment:7 Changed 15 years ago by palgarvio

Ah, dam, forgot about the rendering part :)

comment:8 Changed 15 years ago by palgarvio

  • Resolution set to fixed
  • Status changed from reopened to closed

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

comment:9 Changed 15 years ago by cboos

Fix confirmed, thanks again!

comment:10 Changed 15 years ago by rblank

  • Resolution fixed deleted
  • Status changed from closed to reopened

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.

comment:11 Changed 15 years ago by palgarvio

  • Resolution set to fixed
  • Status changed from reopened to closed

Fixed in [1059].

comment:12 follow-up: Changed 15 years ago by rblank

  • Resolution fixed deleted
  • Status changed from closed to reopened

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>.

comment:13 in reply to: ↑ 12 Changed 15 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.

comment:14 Changed 15 years ago by anonymous

  • Resolution set to fixed
  • Status changed from reopened to closed

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.

comment:15 Changed 15 years ago by rblank

(anonymous was me)

Note: See TracTickets for help on using tickets.