Hi Philipp, You are a great resource, thanks for helping. See below.
> From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] On Behalf Of Philipp > von Weitershausen > Giovannetti, Mark wrote: > > Hi, > > > > 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 zope.app.preference) 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 zope.app.preference stuff stores the info in principal > annotations, in a weird way. I personally find that > stuff a bit convoluted. If you find it convoluted, then how are us mere mortals supposed to deal with it? ;-) > > 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). I'll end up having to do something like this, I suppose. It really sucks, though, because I *want* to use the preferences machinery. Why was it built if it can't be used in certain places - and why aren't the places it can't be used documented? Arrg. > > 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). How am I supposed to deal with what you say above? I don't even understand most of it! ;-) > 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, 'stub this out ... ' - I don't understand, sorry. > 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. I don't know what you mean. How is a noob supposed to deal with this? > The ++lang++ implementation might give some pointers. The ++lang++ implementation (and ensuing errors when I tested using it) told me that I needed to change BrowserFormLanguages to use IModifiableUserPreferredLanguages. Since I had to do that in order to allow language preferences I decided to get the UserPreferences machinery running for the app. Now I have this problem. The *must* be a common use case. Why isn't this already solved and documented as a 'best practice' example? Mark _______________________________________________ Zope3-users mailing list Zope3email@example.com http://mail.zope.org/mailman/listinfo/zope3-users