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;
}
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")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With