[Zope-dev] How can I force the language for a particular	template rendering?
    Hanno Schlichting 
    hannosch at hannosch.eu
       
    Fri Apr 17 15:46:55 EDT 2009
    
    
  
Ethan Jucovy 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..
As the default negotiator is based on the request, it might be possible
to forge a different request object for the template.
Or attach a marker interface to the request and register a different
IUserPreferredLanguages adapter for it. A more specialized version
should take precedence over the normal adapter based on the HTTP header.
Hanno
    
    
More information about the Zope-Dev
mailing list