[Grok-dev] Trigger i18n translation in the rendering method of a view

Sebastian Ware sebastian at urbantalk.se
Mon Sep 26 08:09:12 EST 2011


Thanks for a quick response! Unfortunately I can't get it to work, I did find that call in the PageTemplate implementation, but running translate only returns the original string. However, if I call the view from a PageTemplate: 

   tal:replace="context/@@theview" 

it is in fact translated. 

Do you have this working?

Mvh Sebastian

26 sep 2011 kl. 14.56 skrev Alexandre Garel:

> Le 26/09/2011 14:43, Sebastian Ware a écrit :
>> I can get i18n translation to work fine in PageTemplates, but how do I force translation of text that isn't inserted into templates?
>> 
>> I want to do this and get the string to be translated:
>> 
>>   from . import ApplicationMessageFactory as _
>>   class TestTranslate(grok.View):
>>       def render(self):
>>           return _("I need to be translated")
>> 
>> I have set my breakpoints and I am trying to figure out how the TAL-engine does this, but I am not making much progress.
> 
> In fact  ApplicationMessageFactory  just return a string containing 
> informations for translation.
> 
> You need :
> 
> from zope.i18n import translate
> return translate(_("I need to be translated"))
> 
> and this shall be ok, I think.
> 
> Hope this helps,
> 
> Alex
> _______________________________________________
> Grok-dev mailing list
> Grok-dev at zope.org
> https://mail.zope.org/mailman/listinfo/grok-dev




More information about the Grok-dev mailing list