Is there a nice way to resolve locale based on the URL and in the other hand map requests without any additional requirement ?
For example
http://example.com/ru/news
http://example.com/iw/news
and in the controller still use the standard mappings
@Controller
@RequestMapping(value = "/news")
public class NewsController {
// Controller methods ...
}
I’m not aware of an out-of-the-box solution for this, but it’s easy enough to implement using a custom interceptor and some wisely chosen mappings.
Write an implementation of
HandlerInterceptorwhich implementspreHandleso that the locale string is extracted from the request URI, and then tag the request with that locale (see the source code for the similarLocalChangeInterceptor, which does a similar thing to what you need, but uses a request parameter instead of a path variable).Then wire it up using
<mvc:interceptor>e.g.You can then loosen up the request mapping on your controller to tolerate (and ignore) the locale part of the URI: