I'm pretty sure that _(u'N/A') is creating a MessageFactory message object. No translation is done at that point, as the target language isn't known 'til page rendering.
These message objects are polymorphous, and if you concatenate one to a string: _(u'N/A') + 'oops' or even to another message, the result is a string -- not a message. You need to do the concatenation in the page template. On Fri, Apr 25, 2008 at 11:25 AM, Jean-Pascal Houde <[EMAIL PROTECTED]> wrote: > Hi, > I have a problem with i18n message factories in python files. Perhaps > there's something I don't understand correctly. > > I'm creating a website with PloneGetPaid and trying to add some > translations to PGP. Basically, what I noticed is that if I do the > following in a view: > > def test(self): > return _(u'N/A') > > def test2(self): > return _(u'N/A') + 'oops' > > ... and I try to call it from a page template : > <div tal:content="view/test" /> > <div tal:content="view/test2" /> > > Only the first string is translated correctly. It seems like the > translation is actually occuring during the page template rendering, > and not in the python script (print _(u'N/A') doesn't work either -- > no translation is done). Since the test2 does not return the i18n > message itself, but the message with a string appended to it, it's not > translated at all. > > I'm not sure if this behavior is normal... That's problematic if you > need to create a message from the python script using several message > strings, such as "... %s ... %s" % (_(u'message_1'), _(u'message_2')) > In this case message_1 and message_2 are not translated. > > That's not the first time I'm seeing this problem. It also happened > with another project I did, but I worked around it... Am I doing > something wrong? > > Thanks, > > Jean-Pascal > > _______________________________________________ > Product-Developers mailing list > [email protected] > http://lists.plone.org/mailman/listinfo/product-developers > -- ______________________________________________________ Steve McMahon Reid-McMahon, LLC [EMAIL PROTECTED] [EMAIL PROTECTED] _______________________________________________ Product-Developers mailing list [email protected] http://lists.plone.org/mailman/listinfo/product-developers
