[Grok-dev] Trigger i18n translation in the rendering method of a view
Sebastian Ware
sebastian at urbantalk.se
Mon Sep 26 08:16:26 EST 2011
Turns out one needed to supply the request-object as context. This works:
from zope.i18n import translate
class ForceTranslate(grok.View):
def render(self):
return translate(_("Allt val?"), context=self.request)
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