Edgewall Software

Opened 14 years ago

Last modified 7 years ago

#380 new defect

messages within expressions in py:with directive don't get extracted

Reported by: cboos Owned by: cmlenz
Priority: major Milestone: 0.9
Component: Internationalization Version: 0.5.1
Keywords: Cc: palgarvio

Description

Just noticed that now with [T9454] and [T9455], but it's actually been a while...

Things like:

          <xi:include href="list_of_attachments.html"
                      py:with="alist = attachments; add_button_title = _('Attach another file')"/>

in source:trunk/trac/templates/attachment.html@9400#L86 are there since ages, and no Attach another file in the messages.pot.

Change History (8)

comment:1 follow-up: Changed 14 years ago by cboos

Ah sorry, my reference to [T9454] was a bit confusing...

Take two: while trying to figure out why the two new messages introduced in that revision were not extracted, I realized that the message they replaced was also not extracted before. I then remembered that a gettext _(...) expression within a i18n:msg directive wouldn't be extracted (not sure if there's a ticket for that already, btw). Looking for a workaround, I tried to place those messages in a <py:with> directive, like that:

  • trac/wiki/templates/wiki_view.html

    diff --git a/trac/wiki/templates/wiki_view.html b/trac/wiki/templates/wiki_view.html
    a b  
    4444
    4545      <div class="wikipage searchable" py:choose="" xml:space="preserve">
    4646        <py:when test="page.exists">
    47           <div py:if="not version" class="trac-modifiedby" i18n:msg="reldate">
    48             <a href="${href.wiki(page.name, action='diff', version=page.version)}"
    49                title="${page.comment and _('Version %(version)s by %(author)s: %(comment)s',
    50                                            version=page.version, author=format_author(page.author), comment=page.comment)
    51                                      or _('Version %(version)s by %(author)s',
    52                                           version=page.version, author=format_author(page.author))}">
    53               Last modified</a> ${dateinfo(page.time)} ago
    54           </div>
     47          <py:with vars="last_mod_comment = _('Version %(version)s by %(author)s: %(comment)s',
     48                                              version=page.version, author=format_author(page.author),
     49                                              comment=page.comment);
     50                         last_mod = _('Version %(version)s by %(author)s',
     51                                      version=page.version, author=format_author(page.author))">
     52            <div py:if="not version" class="trac-modifiedby" i18n:msg="reldate">
     53              <a href="${href.wiki(page.name, action='diff', version=page.version)}"
     54                 title="${page.comment and last_mod_comment or last_mod}">Last modified</a>
     55                 ${dateinfo(page.time)} ago
     56            </div>
     57          </py:with>
    5558          <div id="wikipage" py:content="wiki_to_html(context, text)" />
    5659        </py:when>
    5760        <py:otherwise>

Alas, no luck for this one as well, hence this ticket.

Would be nice to fix either of those two extraction issues, or suggest another workaround...

comment:2 Changed 14 years ago by cboos

Just found a workaround: using a <?python ?> PI instead of the <py:with>, see [T9456].

Still...

comment:3 in reply to: ↑ 1 Changed 14 years ago by cmlenz

  • Status changed from new to assigned

Replying to cboos:

Take two: while trying to figure out why the two new messages introduced in that revision were not extracted, I realized that the message they replaced was also not extracted before. I then remembered that a gettext _(...) expression within a i18n:msg directive wouldn't be extracted (not sure if there's a ticket for that already, btw). Looking for a workaround, I tried to place those messages in a <py:with> directive, like that:

So part of the underlying problem was that attribute values in markup embedded in i18n:msg and i18n:choose directives would not get extracted. This should be fixed in [1115].

I still need to add unit tests for the case where you have actual gettext() function calls in attribute values, but I think that should also work now.

comment:4 Changed 14 years ago by cboos

Remaining problems in Trac concerning this topic, if I do the following changes to get rid of the <?python ... ?> trick:

  • trac/templates/attachment.html

    diff --git a/trac/templates/attachment.html b/trac/templates/attachment.html
    a b  
    8282
    8383      <py:when test="'list'">
    8484        <h1><a href="${url_of(parent)}">${name_of(parent)}</a></h1>
    85         <py:with vars="context = context(parent)">
    86           <?python add_button_title = _('Attach another file') ?>
     85        <py:with vars="context = context(parent);
     86                       add_button_title = _('Attach another file')">
    8787          <xi:include href="list_of_attachments.html" py:with="alist = attachments"/>
    8888        </py:with>
    8989      </py:when>
  • trac/wiki/templates/wiki_view.html

    diff --git a/trac/wiki/templates/wiki_view.html b/trac/wiki/templates/wiki_view.html
    a b  
    4242        </table>
    4343      </py:if>
    4444
    45       <div class="wikipage searchable" py:choose="" xml:space="preserve">
    46         <py:when test="page.exists">
    47           <?python
     45      <div class="wikipage searchable" py:choose="" xml:space="preserve"
     46          py:with="
    4847            last_modification = (page.comment and
    4948                 _('Version %(version)s by %(author)s: %(comment)s',
    5049                   version=page.version, author=format_author(page.author), comment=page.comment) or
    5150                 _('Version %(version)s by %(author)s',
    52                    version=page.version, author=format_author(page.author)))
    53           ?>
     51                   version=page.version, author=format_author(page.author)))"
     52        >
     53        <py:when test="page.exists">
    5454          <div py:if="not version" class="trac-modifiedby" i18n:msg="reldate">
    5555            <a href="${href.wiki(page.name, action='diff', version=page.version)}"
    5656               title="$last_modification">Last modified</a> ${dateinfo(page.time)} ago

I then lose the messages after doing an extraction (Genshi 0.6, Babel 0.9.5):

  • trac/locale/messages.pot

    diff --git a/trac/locale/messages.pot b/trac/locale/messages.pot
    a b msgid "" 
    88msgstr ""
    99"Project-Id-Version: Trac 0.12\n"
    1010"Report-Msgid-Bugs-To: trac-dev@googlegroups.com\n"
    11 "POT-Creation-Date: 2010-04-23 11:25+0200\n"
     11"POT-Creation-Date: 2010-04-23 11:35+0200\n"
    1212"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
    1313"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
    1414"Language-Team: LANGUAGE <LL@li.org>\n"
    msgstr "" 
    15851585msgid "Delete attachment"
    15861586msgstr ""
    15871587
    1588 #: trac/templates/attachment.html:86
    1589 msgid "Attach another file"
    1590 msgstr ""
    1591 
    15921588#: trac/templates/attachment.html:98 trac/templates/list_of_attachments.html:22
    15931589#: trac/templates/macros.html:19 trac/versioncontrol/templates/browser.html:110
    15941590#: trac/versioncontrol/templates/dir_entries.html:16
    msgid "" 
    53435339"               ([1:diff])"
    53445340msgstr ""
    53455341
    5346 #: trac/wiki/templates/wiki_view.html:47
    5347 #, python-format
    5348 msgid "Version %(version)s by %(author)s: %(comment)s"
    5349 msgstr ""
    5350 
    5351 #: trac/wiki/templates/wiki_view.html:47
    5352 #, python-format
    5353 msgid "Version %(version)s by %(author)s"
    5354 msgstr ""
    5355 
    53565342#: trac/wiki/templates/wiki_view.html:54
    53575343#, python-format
    53585344msgid "[1:Last modified] %(reldate)s ago"

comment:5 Changed 14 years ago by cmlenz

  • Milestone changed from 0.7 to 0.6.1
  • Status changed from assigned to new

comment:6 follow-up: Changed 14 years ago by Carsten Klein <carsten.klein@…>

I am a bit confused. So you are setting the variable add_button_title. But where are you actually using this variable?

comment:7 in reply to: ↑ 6 Changed 14 years ago by Carsten Klein <carsten.klein@…>

Replying to Carsten Klein <carsten.klein@…>:

I am a bit confused. So you are setting the variable add_button_title. But where are you actually using this variable?

-> forget this, stupid me. Must have been late.

comment:8 Changed 7 years ago by hodgestar

  • Milestone changed from 0.6.1 to 0.9

Move to milestone 0.9.

Note: See TracTickets for help on using tickets.