Feb 2nd, 2007, 09:05 AM
How to set the Locale for Tag use ?
from my requirement I don't have to use the Locale from the request, but using a business rule.
So I have to use a application-defined Locale for I18N, using the Spring taglib.
But in the source code I found (TagMessageI18N.java):
return messageSource.getMessage(resolvedMessage, getRequestContext().getLocale());
How can I set the Locale in the RequestContext ? As I understand the requestContext harvests the Locale from the request, exactly the opposite I want to perform.
Thank you for your help.
Feb 2nd, 2007, 09:12 AM
There is a interceptor which can switch the Locale (conveniently named LocaleChangeInterceptor). The current implementation uses a property on the request to switch the Locale. But you can ofcourse make your own implementation which uses your Business Rule(s).
Hmm just looking a bit further, you can also create a LocalResolver (there is already an abstract class) which you can register in your application context, that in combination with the default LocaleChangeInterceptor will switch your locale.
Feb 2nd, 2007, 09:27 AM
ok thanks a lot.
will try to do that :-)
Feb 2nd, 2007, 09:39 AM
one more question about LocaleResolver.
(warning, I'm a newbie)
Where do I need to declare my new implementation of LocaleResolver ?
Feb 2nd, 2007, 04:48 PM
In your applicationContext with the other beans. You have to name it localeResolver and that should do the trick.