+1

On May 5, 12:39 pm, mdipierro <mdipie...@cs.depaul.edu> wrote:
> +1
>
> On May 5, 12:29 pm, Mariano Reingart <reing...@gmail.com> wrote:
>
> > Advice:
>
> > Using translated strings as keys is a very bad idea (sorry, my fault).
>
> > As soon as other language is used, dictionaries and lists are broken
> > anyway (some values stored translated, some other stored
> > untranslated...)
>
> > I think it is better to allways use untranslated strings internally
> > (in key, lists, fields), and then translate them at the view.
>
> > Best regards,
>
> > Mariano 
> > Reingarthttp://www.aprug.com.arhttp://www.sistemasagiles.com.arhttp://reingar...
>
> > On Tue, May 4, 2010 at 8:45 PM, Mariano Reingart <reing...@gmail.com> wrote:
> > > Seems translated texts cannot be used as keys for dictionaries or
> > > values to be iterated for lists/tuples:
>
> > > SPONSOR_LEVELS=(T("Organizer"),T("Sponsor"))
> > > ...
> > > random.shuffle(response.sponsors[SPONSOR_LEVELS[1]])
>
> > > Traceback (most recent call last):
> > >  File "gluon/restricted.py", line 178, in restricted
> > >    exec ccode in environment
> > >  File "/home/web2py/applications/rafaela2010/models/menu.py", line
> > > 85, in <module>
> > >    random.shuffle(response.sponsors[SPONSOR_LEVELS[1]])
> > > KeyError: <gluon.languages.lazyT object at 0x89620ec>
>
> > > Iterating over a T'ed values causes the same bug:
>
> > > Traceback (most recent call last):
> > >  File "gluon/restricted.py", line 178, in restricted
> > >    exec ccode in environment
> > >  File "/home/web2py/applications/raf10dev/views/plugin_flatpages.html",
> > > line 112, in <module>
> > >    for sponsor_level in SPONSOR_LEVELS:
> > > KeyError: <gluon.languages.lazyT object at 0x89e2f4c>
>
> > > Workaround:
> > > ------------------
>
> > > Converting translated text to str solves the problem:
>
> > > random.shuffle(response.sponsors[str(SPONSOR_LEVELS[1])])
>
> > > or
>
> > > for sponsor_level in [str(l) for l in SPONSOR_LEVELS]:
>
> > > Best regards,
>
> > > Mariano Reingart
> > >http://www.sistemasagiles.com.ar
> > >http://reingart.blogspot.com

Reply via email to