[Grok-dev] Chameleon and i18n
Sylvain Boureliou
sylvain.boureliou at makina-corpus.com
Wed Feb 10 04:03:36 EST 2010
Vincent Fretin a écrit :
> On Tue, Feb 9, 2010 at 3:38 PM, Sylvain Viollon <sylvain at infrae.com> wrote:
>
>> On Tue, 9 Feb 2010 15:23:12 +0100
>> Souheil CHELFOUH <trollfot at gmail.com> wrote:
>>
>> Hello,
>>
>>
>>> I think that the request language is not taken by default so it's
>>> always considered as english.
>>> You can have a look here :
>>> http://chameleon.repoze.org/docs/latest/i18n.html Have a look at the
>>> i18n:target.
>>>
>>>
>>>
>> Or you can set target_language in your namespace on your view:
>>
>> def namespace(self):
>> return {'target_language': 'fr'}
>>
>
> Really? You have to do this yourself?
> The question is how the classic pagetemplate works in this case? I'm
> really interested to know that.
>
> In this case, maybe you can make this dynamic with:
> self.request.locale.getLocaleID()
> u'fr_FR'
>
> self.request.locale is already the result of an
> IUserPreferredLanguages, I think the one registered in
> zope/publisher/browser.py
> The code which set request.locale is in
> zope.publisher/http.py:HTTPRequest.setupLocale
>
> Vincent
> _______________________________________________
> Grok-dev mailing list
> Grok-dev at zope.org
> https://mail.zope.org/mailman/listinfo/grok-dev
>
Thanks for your answers. I use the following base view for all my views
and it works perfectly:
class BaseView(grok.View):
"""."""
grok.baseclass()
def namespace(self):
return {'target_language': self.request.locale.getLocaleID()}
getLocaleID() returns the same result as:
from zope.publisher.browser import BrowserLanguages
lang =
unicode(BrowserLanguages(self.request).getPreferredLanguages()[0])
Sylvain
--
Sylvain Boureliou, Ingénieur Zope/Python/Plone
MAKINA CORPUS - www.makina-corpus.com
44 Boulevard des pas enchantés FR-44230 Saint Sébastien Sur Loire
T : +33 (0) 2 51 79 80 80
Email : sylvain.boureliou at makina-corpus.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.zope.org/pipermail/grok-dev/attachments/20100210/eafef923/attachment.html
More information about the Grok-dev
mailing list