Do you know, what locale gets injected here (ThreadLocale's, Request's or PersistentLocale's)? The
docs just say "The locale of the component" so I'd guess ThreadLocale's, but I'm not sure...
Uli
Geoff Callender schrieb:
Not sure if I'm answering your question, but there's also
@Inject
private Locale _currentLocale;
For an example of it in action try
http://localhost:8080/jumpstart/examples/localization/bymessagecatalog .
Geoff
On 20/09/2008, at 12:19 AM, José Paumard wrote:
Ulrich,
Many thanks for your very precise answer ! Indeed
threadLocale.getLocale() is the way to go.
José
Ulrich Stärk a écrit :
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
---------------------------------------------------------------------
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]