views:

146

answers:

1

I have a spring web application that is required to work as following

the application will be accessed from two different URLs www.domain1.com and www.domain2.com

and it is required that the two URLs looks like two different applications with different CSS and I18n.

for the css part is done but I am stuck with the i18n part

How to make spring load different i18n properties file according to the domain name?

The solution that I thought in is to implement a filter that check the request URL and according to the URL it clears the message source bean and load the required i18n file but it does not looks good for the performance

by the way I am using ReloadableResourceBundleMessageSource message source

Another solution is to implement two different message sources. The problem with this solution is that from the source code I can manage the bean that I use but how can I tell the fmt:message tag which data source to use ?

Thanks in advance and best regards

A: 

I suggest using a LocaleResolver. This is a standard Spring interface for doing exactly this sort of thing.

Interface for web-based locale resolution strategies that allows for both locale resolution via the request and locale modification via request and response.

This interface allows for implementations based on request, session, cookies, etc.

The pre-defined implementations of LocaleResolver don't do what you need, but it's trivial to write your own. Your implementation would be asked by to determine the locale for each request, and this information is then used by Spring's i18n code, including ReloadableResourceBundleMessageSource. You just declare your LocaleResolver bean in the context, and it's picked up automatically.

Your resource bundles would then use standard java locale mechanism to resolve the correct message for the current locale.

skaffman
Thanks skaffman for your reply.May be I do not understand this well but here is what I know.The local resolver works behind a localeChangeInterceptor.The interceptor accepts one parameter that indicates the local.In my situation I need two params one for the local and another for the domain (in my app we call it virtual site).If I understand well I will need to reimplement the interceptor and the resolver not just the resolver and in this case the properties files that I will use will follow another pattern like application_local_virtualSit.properties?Is that doable ? I do not think so.
Fanooos
@Fanooos: `LocaleChangeInterceptor` is not necessary, that's only for special circumstances. `LocaleResolver` works with many parts of the Spring framework (e.g. with `DispatcherServlet`).
skaffman