I18n in Spring boot + Thymeleaf I18n in Spring boot + Thymeleaf spring spring

I18n in Spring boot + Thymeleaf


Your application should extends WebMvcConfigurerAdapter

@SpringBootApplicationpublic class NerveNetApplication extends WebMvcConfigurerAdapter {    public static void main(String[] args) {        SpringApplication.run(NerveNetApplication.class, args);    }    @Bean    public LocaleResolver localeResolver() {        return new CookieLocaleResolver();    }    @Bean    public LocaleChangeInterceptor localeChangeInterceptor() {        LocaleChangeInterceptor lci = new LocaleChangeInterceptor();        lci.setParamName("lang");        return lci;    }    @Override    public void addInterceptors(InterceptorRegistry registry) {        registry.addInterceptor(localeChangeInterceptor());    }}

Then on browser you can switch language with param langExample: http://localhost:1111/?lang=kh which messages_kh.properites will store the content of Khmer language.