[Zope-dev] How can I force the language for a particular template rendering?

Ethan Jucovy ethan.jucovy at gmail.com
Fri Apr 17 15:48:29 EDT 2009


Actually -- for a more proper solution -- I believe
zope.i18n.interfaces.IUserPreferredLanguages is expected to adapt a request
(rather than being a contextless utility) so I bet you could register a
custom IUserPreferredLanguages whose getPreferredLanguages returns ['fr'] on
an IForceLanguage interface, and mark the current request with
IForceLanguage before rendering the template.

egj

On Fri, Apr 17, 2009 at 3:35 PM, Ethan Jucovy <ethan.jucovy at gmail.com>wrote:

> How about just monkeypatching the active negotiator?
>
> {{{
> negotiator = getUtility(zope.i18n.interfaces.INegotiator)
> orig = negotiator.getLanguage
> negotiator.getLanguage = lambda foo, bar: 'fr'
> text = my_page_template()
> negotiator.getLanguage = orig
> }}}
>
> Haven't tested it, but in my (limited) understanding of the I18N system
> something like that ought to work..
>
> egj
>
>
> On Fri, Apr 17, 2009 at 3:14 PM, Chris Withers <chris at simplistix.co.uk>wrote:
>
>> Hi All,
>>
>> What I want to do is best shown in pseudocode:
>>
>> something.setLanguage('fr')
>> text = my_page_template()
>> something.restoreLanguage()
>>
>> ...the reason I want to do this is that the results of that template
>> will not be in the language negotiated for the current user, as the
>> result is then emailed to someone who may not be speaking the same
>> language as them.
>>
>> I can't find a way to specify a target_language that overrides the
>> negotiated language into the ZPT rendering process. Is there such a way?
>>
>> Suggestions welcomed!
>>
>> Chris
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.zope.org/pipermail/zope-dev/attachments/20090417/5d09cdd0/attachment-0001.html 


More information about the Zope-Dev mailing list