Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Locale in Spring

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;
}
like image 313
Julia Bel Avatar asked Oct 19 '22 00:10

Julia Bel


1 Answers

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")
like image 180
Arne Burmeister Avatar answered Nov 15 '22 03:11

Arne Burmeister