Im trying to build my first Spring MVC 4 app with i18n support and was thinking how i can use a default/fallback locale in case of the user is manipulating the language uri parameter to a non existing or supported locale For example http://localhost.de?lang=abc
Im using the code
@Bean
public LocaleResolver localeResolver() {
SessionLocaleResolver sessionLocaleResolver = new SessionLocaleResolver();
sessionLocaleResolver.setDefaultLocale(Locale.GERMAN);
return sessionLocaleResolver;
}
which works in general if i open the url the very first time but it seems not to work for the case i was describing. I know there is a mechanism which would use the default messages properties file but i would like to set a default/fallback locale for this case. Do i need to implement maybe a custom filter?
My suggestion would be to subclass the SessionLocaleResolver and override the getLocale method:
This does not modify the Spring classes in any major way and is probably going to work without issues for the foreseeable future.