I'm not 100% firm in this area but I believe that the user's locale gets stored in the ThreadLocale service. This service is responsible for storing the current thread's locale, i.e. the locale for which pages, messages etc. are being generated. The locale in ThreadLocale gets set by a combination of various other services.

One of them is the PersistentLocale service. If you call persistentLocale.set(locale) a cookie is sent to the browser storing the desired locale. If you call persistentLocale.get() that value is read and returned. If no cookie has been set, this will be null. You can check that with persistentLocale.isSet().

persistentLocale.set() also overwrites the locale in the ThreadLocale service. If the desired locale is not in supported-locales, Tapestry chooses the nearest matching locale. Thus, querying the ThreadLocale service will give you the locale that Tapestry has chosen to generate pages, messages etc. in, taking into account PersistentLocale's value as well as the Request's locale.

So there are 3 ways to get the locale:

- request.getLocale() will give you the locale, that the browser sent
- persistentLocale.get() will give you the locale stored in a cookie in the user's browser or null, if no cookie is set - threadLocale.getLocale() will give you the locale choosen by Tapestry, taking into account the Request's locale, PersistentLocale's locale (will be chosen over the Request's locale) and supported-locales.

HTH.

Cheers,

Uli

José Paumard schrieb:
Hello all,

I know this looks like a faq, but to be sure, is T5 supposed to set the current locale (the one we get by calling persistentLocale.get()) on each request, and does it work ? My problem is that I get null when I call persistentLocale.get(), with a locale set when I call request.getLocale(), and corresponding to a declared locale in tapestry.supported-locale. Am I missing something ?

Any info would be much appreciated,

José


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to