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

Souheil CHELFOUH trollfot at gmail.com
Mon Sep 26 08:17:46 EST 2011


This is because the request is the object containing the browser
information related to the language, it's all stored in the Locales
object in the request

2011/9/26 Sebastian Ware <sebastian at urbantalk.se>:
> 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
>
>
> _______________________________________________
> 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