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. Mvh Sebastian _______________________________________________ Grok-dev mailing list [hidden email] https://mail.zope.org/mailman/listinfo/grok-dev |
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 [hidden email] https://mail.zope.org/mailman/listinfo/grok-dev |
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 > [hidden email] > https://mail.zope.org/mailman/listinfo/grok-dev _______________________________________________ Grok-dev mailing list [hidden email] https://mail.zope.org/mailman/listinfo/grok-dev |
In reply to this post by Alexandre Garel-2
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 > [hidden email] > https://mail.zope.org/mailman/listinfo/grok-dev _______________________________________________ Grok-dev mailing list [hidden email] https://mail.zope.org/mailman/listinfo/grok-dev |
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 <[hidden email]>: > 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 >> [hidden email] >> https://mail.zope.org/mailman/listinfo/grok-dev > > > _______________________________________________ > Grok-dev mailing list > [hidden email] > https://mail.zope.org/mailman/listinfo/grok-dev > Grok-dev mailing list [hidden email] https://mail.zope.org/mailman/listinfo/grok-dev |
Thanks!
It seems that I will need to do something like this to make the code concise. Does this look reasonable? from translation import ApplicationMessageFactory as MsgF from zope.i18n import translate class HelpTranslate(grok.View): def render(self): def _(txt): return translate(MsgF(txt), context=self.request) outp = [] outp.append(_("Alla glada?")) return "".join(outp) Mvh Sebastian 26 sep 2011 kl. 15.17 skrev Souheil CHELFOUH: > 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 <[hidden email]>: >> 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 >>> [hidden email] >>> https://mail.zope.org/mailman/listinfo/grok-dev >> >> >> _______________________________________________ >> Grok-dev mailing list >> [hidden email] >> https://mail.zope.org/mailman/listinfo/grok-dev >> _______________________________________________ Grok-dev mailing list [hidden email] https://mail.zope.org/mailman/listinfo/grok-dev |
Free forum by Nabble | Edit this page |