On Sat, Apr 18, 2009 at 12:34:19AM +0100, Chris Withers wrote: > Hanno Schlichting wrote: > > Or attach a marker interface to the request and register a different > > IUserPreferredLanguages adapter for it. > > This won't quite work as I still need to get the language I'm forcing > from somewhere. > > However, I realised I already had a custom IUserPreferredLanguages > adapter on this project (to get the language from the user object, not > the browser) so I added a bit of code in there. The simplest version of > this would be: > > from zope.publisher.browser import BrowserLanguages > > class Languages(BrowserLanguages): > > def getPreferredLanguages(self): > force = getattr(self.request,'_force_language',None) > if force: > return [force] > return super(Languages, self).getPreferredLanguages() > > Then this zcml: > > <adapter > for="zope.publisher.interfaces.http.IHTTPRequest" > provides="zope.i18n.interfaces.IUserPreferredLanguages" > factory=".languages.Languages" > /> > > ...and then you can do the following in a view: > > def __call__(self): > def1 = self.template(self) > self.request._force_language = 'de'
Does this work? IIRC Zope 3 request objects use __slots__ and therefore cannot have any extra attributes imposed upon them from the outside. Marius Gedminas -- http://pov.lt/ -- Zope 3 consulting and development
signature.asc
Description: Digital signature
_______________________________________________ Zope-Dev maillist - [email protected] http://mail.zope.org/mailman/listinfo/zope-dev ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope )
