Forum OpenACS Improvement Proposals (TIPs): Tip #104 (Approved): Locale cookie

In a recent use case I came up with the need for having an explicit locale for not logged in users, overwriting the browsers default language (https://openacs.org/forums/message-view?message_id=544412).

My proposal would be to write a procedure "lang::locale::set_cookie -locale" which will set a cookie "ad_lang_locale" to a certain locale for the user. Additionally write a procedure lang::locale::get_cookie which will retrieve the cookie's value.

lang::conn::locale would then be modified as per Gustaf's suggestion to first check if the user is logged in, then proceed as current. Afterwards, before checking the browser setting, it would try to retrieve the cookie and use the cookie's value (not the browser setting).

Once a user is registering, the locale to be stored in user_preferences will be taken from the cookie or the browser setting.

The question now is, should the cookie by cleared when the user registers or should it be reset when the locale of a user is changed. I would opt for the later as it would make sure the user is viewing the site even when not logged in, in the locale of his choosing.

But if we are keeping the cookie in sync with the locale of the user anyway, we could as well use the cookie instead of making a roundtrip to the database to figure out the user's locale. Then the cookie would be reset every time the user logs into the system.

For my use case it would be enough to implement only the first three paragraphs of this TIP (so no keeping in sync and rewrite of lang::conn:locale to first check the cookie and then the database), but I would like to hear first what others think how far the change should go. I will implement the changes accordingly for 5.4

Collapse
Posted by Gustaf Neumann on
Hmm,
was this my suggestion?

i would try to keep this as simple as possible to avoid confusions.
a) don't expire the cookie
b) the cookies takes alway priority over database.
c) if the user changes her locale, the cookie is changed as well to the new value.
d) when the cookie is set, acs-lang (reached via pvt/home) should say, that the current locale is set via cookie, and give an option to clear the cookie.

Collapse
Posted by Don Baccus on
with Gustaf's additions
Collapse
Posted by Malte Sussdorff on
I vote yes for the method suggested by Gustaf.
Collapse
Posted by Dave Bauer on
Approved
Collapse
Posted by Gustaf Neumann on
approved
Collapse
Posted by Michael Aram on
is this part of openacs 5.3 as described?

we use an early checkout of openacs 5.3, which sets a cookie, if a user is not logged in. the cookie's value is updated on every language change.

but when logged in, the cookie's value is overridden by the user's settings (and left untouched).

of course - on log out - the cookie's value is used again.

Our acs-lang/tcl/locale-procs.tcl (where I think the magic happens - isn't it?) is the same as the one in HEAD.

(Also, I couldn't find any procedure named as above)...