[Grok-dev] Trigger i18n translation in the rendering method of a view
alex.garel at tarentis.com
Mon Sep 26 07:56:47 EST 2011
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,
More information about the Grok-dev