hm. I do not really follow. I'll try to explain my problem in more detail. First, I only use Chameleon from within deform, the rest of my app uses mako. Now I noticed that form rendering was slow and that was because of the template loader parsing the templates all the time. As far as I can see in chameleon.loader, the caching is done per instance of TemplateLoader. Now deform instantiates a TemplateLoader when a deform.template.ZPTRendererFactory is instantiated. When using the default_renderer this is only done once on import of deform and caching will work - i guess. But to be able to pass a translator per request, I instantiate a new ZPTRendererFactory per request as well - and no caching is possible. Now my workaround was to instantiate one ZPTRendererFactory per supported locale at app startup, and set its translator upon the first request having this locale (using get_localizer which does the lookups you describe below). So maybe my problems only come up because i do not use pyramid's chameleon integration? regards robert
On Fri, Aug 12, 2011 at 9:13 AM, Malthe Borch <[email protected]> wrote: > On 11 August 2011 19:33, Robert Forkel <[email protected]> wrote: >> Yes, that's what I'm doing now. Right now it's sort of tied to the >> TemplateLoader, though - at least the way deform uses Chameleon. So >> what I do is keep the zpt renderers around and assign to >> renderer.loader.kwargs['translate'] per request - not exactly a nice >> API to do that. > > You should never need to do this manually. It's handled by the framework. > > What you need to do is to make sure the locale is set up for each request: > > - First, the negotiator looks for the ``_LOCALE_`` attribute of > the request object (possibly set by a view or a listener for an > :term:`event`). > > - Then it looks for the ``request.params['_LOCALE_']`` value. > > - Then it looks for the ``request.cookies['_LOCALE_']`` value. > > - Finally, the negotiator returns ``None`` if the locale could not > be determined via any of the previous checks (when a locale > negotiator returns ``None``, it signifies that the > :term:`default locale name` should be used.) > > You can subscribe to the ``INewRequest`` event to set this up per request. > > \malthe > > -- > You received this message because you are subscribed to the Google Groups > "pylons-discuss" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]. > For more options, visit this group at > http://groups.google.com/group/pylons-discuss?hl=en. > > -- You received this message because you are subscribed to the Google Groups "pylons-discuss" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/pylons-discuss?hl=en.
