tholu
tholu

Reputation: 1142

Java Spring: localeChangeInterceptor and subdomains

I have a Spring MVC webapp and want to do this (example):

I already use the localeChangeInterceptor to change the language by URL parameter on request, and this works (adding a parameter e.g. ?lang=en to my URLs).

But what is the best way to have language-specific subdomains with Spring? I searched the web and Spring documentation, but have yet to find an answer.

I think it could work like this:

  1. Intercept any request
  2. Determine used subdomain
  3. Decide which language/locale should be used and set it like the localeChangeInterceptor does

If this is the way to go, I could use a hint where to start.

Thanks in advance!

Upvotes: 1

Views: 1147

Answers (1)

aweigold
aweigold

Reputation: 6879

You will want to implement your own LocaleResolver.

The LocaleResolver.resolveLocale(HttpServletRequest) method is what Spring uses to determine which Locale to use from the MessageSource. You can extract the subdomain from the request and return the desired Locale.

Upvotes: 3

Related Questions