Edgewall Software

Ticket #250 (new defect)

Opened 4 months ago

Last modified 4 months ago

Error with I18n filter in Trac

Reported by: cmlenz Owned by: cmlenz
Priority: major Milestone: 0.5.2
Component: Internationalization Version: 0.5.1
Keywords: Cc:

Attachments

ticket250.diff (1.6 KB) - added by cmlenz 4 months ago.
Proposed fix

Change History

Changed 4 months ago by cmlenz

Proposed fix

Changed 4 months ago by palgarvio

Apparently it's still not good enough.

Consider the following html snippet:

<h2 i18n:msg="locale, display_name, english_name">
  Messages for <span>$locale.locale</span> &mdash;
  <span xml:lang="$locale.locale">$locale.locale.display_name</span>
  &mdash; <span>$locale.locale.english_name</span>
  <span class="numresults">(${messages.displayed_items()})</span>
  <a class="contribute" href="${req.href.translate(locale.catalog.id, locale.locale)}">
    Help Translate
  </a>
</h2>

This one outputs this traceback.

For this there's an easy fix, change the i18n:msg attribute to include another variable name.

<h2 i18n:msg="locale, locale, display_name, english_name">
  Messages for <span>$locale.locale</span> &mdash;
  <span xml:lang="$locale.locale">$locale.locale.display_name</span>
  &mdash; <span>$locale.locale.english_name</span>
  <span class="numresults">(${messages.displayed_items()})</span>
  <a class="contribute" href="${req.href.translate(locale.catalog.id, locale.locale)}">
    Help Translate
  </a>
</h2>

I repeated locale because I wan't the same text in both:

<span>$locale.locale</span>

and:

<span xml:lang="$locale.locale">( ..... )</span>

It's the same $locale.locale expression.

But what happens there get's the following output:

<h2>Messages for <span>Deutsch</span><span xml:lang="de" lang="de">Deutsch</span><span>German</span>
  <span class="numresults">(1 - 5 of 5)
  <a class="contribute" href="/translate/1/de">
    Help Translate
  </a></span>
</h2>

What seems to happen is that the first locale var get's the value of $locale.locale, the 2nd locale var does not get the value of $locale.locale because it's an attribute and it even is the ignored xml:lang attribute(i18n'wise), instead it get's the value of $locale.locale.display_name, which is not correct and reassigning a new value to the var locale.

Changed 4 months ago by palgarvio

Forgot to say that if I name both var difently, ie, for example, locale1 and locale2, it works perfectly, yet, might be the best behaviour?

Changed 4 months ago by palgarvio

Nevermind, I forgot to get a var name for also messages.displayed_items().

Anyway, we should raise a more explicit exception, IndexError might not immediately lead the coder to the right spot.

Add/Change #250 (Error with I18n filter in Trac)

Author



Change Properties
<Author field>
Action
as new
as The resolution will be set. Next status will be 'closed'
to The owner will change from cmlenz. Next status will be 'new'
The owner will change from cmlenz to anonymous. Next status will be 'assigned'
 
Note: See TracTickets for help on using tickets.