Reputation: 347
I am trying to use the LocaleResolver
from Spring to change my page language when user wants. The initial language should be Portuguese, but it's not working as expected:
@Bean
public LocaleResolver localeResolver() {
CookieLocaleResolver localeResolver = new CookieLocaleResolver();
localeResolver.setDefaultLocale(new Locale("pt-BR"));//StringUtils.parseLocaleString("en")
return localeResolver;
}
Upvotes: 5
Views: 1784
Reputation: 20614
I am not sure what you mean with "but it's not working as expected" but you use the Locale constructor the wrong way. First language and country are separated by an underscore not a minus and the single String argument constructor is for language only. So you have two valid options:
new Locale("pt", "BR")
or
StringUtils.parseLocaleString("pt_BR")
Upvotes: 3