Giovannetti, Mark wrote:

This stuff is crazy.  I just want to implement a user
preference for a language (because I have to).  I've
read all the user pref. documentation (skinpref, apidoc
prefs and until I'm blue in the
face.  Nothing seems to work and there is no help via
google and so forth.

I know that UserPreferences() wants an ILocation object.
I can't seem to get one inside the BrowserFormLanguages
class.  I am only given the request object.

What do I need to do?  Getting a root site is insane
the way I found to do it via a mailing list message.  Not
to mention it had issues racking up db connections, then
failing on close.

Help! Please! Thank you!

Preferences seem to work since I can edit them using
the http://.../++preferences++/ form.

The stuff stores the info in principal annotations, in a weird way. I personally find that stuff a bit convoluted.

The key, as you've correctly identified, is write your own IUserPreferredLanguages adapter (or a variant thereof). I would store the user's preferences in a cookie or a session. This makes things much easier. Simply adapt the request to ISession(request).

Note that this might not always work, e.g. when the request is instantiated and the request's locale is first created (because local utilities to store the session data in aren't available at that point). It seems you're hitting that exact problem with the preference stuff as well. The trick here is to stub this out when the adapter is first called, and then later during traversal, when you know the local components are there, you revisit it all again by calling request.setUpLocale() or whatever it is. The ++lang++ implementation might give some pointers.

-- -- Professional Zope documentation and training
Next Zope 3 training at Camp5:

Zope3-users mailing list

Reply via email to