Edgewall Software

Ticket #250 (closed defect: fixed)

Opened 11 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 Download (1.6 KB) - added by cmlenz 11 months ago.
Proposed fix

Change History

Changed 11 months ago by cmlenz

Proposed fix

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

Changed 4 months ago by cmlenz

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

The above patch was checked in to trunk in [927] and ported to 0.5.x in [947]. s0undt3ch, If there's anything here that still needs attention, please open a new ticket. But I suspect it's all working dandily on advanced-i18n anyway :)

Changed 4 months ago by palgarvio

Yep, advanced-i18n is ready for your hands :)

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

Author


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


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