On Fri, Apr 17, 2009 at 03:35:58PM -0400, 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..
Two words: "thread safety". Zope 3 utilities are global, not thread-local. Unless you have a persistent utility (theoretically; the default INegotiator isn't), which would be thread-local. (And in which case your example code would try to pickle a bound method---I wonder if that'd work? I think it might, but just consider the conflict errors you'd get if every request did this.) "Monkey-patching outside unit tests is evil and will explode when you don't expect" is a good rule of thumb. Marius Gedminas -- http://pov.lt/ -- Zope 3 consulting and development
signature.asc
Description: Digital signature
_______________________________________________ Zope-Dev maillist - Zope-Dev@zope.org 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 )