Google recommends to use country specific (toplevel) domains, subdomains or subdirectories to indicate the locale of a sites content.
Spring provides out of the box support for url parameters to change the locale of a site (explicitly not recommended by google) when using a LocaleChangeInterceptor. It should be relatively easy to create an interceptor that extracts the locale from the TLD or a subdomain, but creating "directories" that indicate the locale is not possible as of spring 4.1.4 in a noninvasive way.
The urls should look like this:
It is easy to write an interceptor/localeResolver to extract the locale part from the url. But request mapping becomes a pain, because every controller must be aware of the locale that is present in the url. It becomes more difficult, if one would like
to point to an automatically evaluated locale (AcceptHeaderLocale, IP lookup, default locale).
I tried to solve the problem by extending UrlPathHelper to strip the locale part from the url. Then the mapping becomes easy again.
The problem is, that the MvcUriComponentsBuilder is not aware of the fact that there is some stripped part of the url. At least when using the spring url tag library to construct urls from controller methods (the tag utilizes MvcUriComponentsBuilder#fromMappingName), the stripped part is lost. I didn't test it, but all factory methods of MvcUriComponentsBuilder should lose the locale part.
It should be possible to to configure a strategy to manipulate the retrieved url path, like it is possible for controller method arguments using UriComponentsContributor s. With such a strategy, it should be possible to restore the stripped part of the url.