我使用spring i18n在我的网站上设置了两种语言。默认语言是X.如果用户来自X以外的其他国家/地区,我的目标是找到设置英语的最佳方式。
我的春季配置:
...
@Bean
public LocaleResolver localeResolver(){
CookieLocaleResolver resolver = new CookieLocaleResolver();
resolver.setDefaultLocale(new Locale("x"));
resolver.setCookieName("myLocaleCookie");
resolver.setCookieMaxAge(4800);
return resolver;
}
@Override
public void addInterceptors(InterceptorRegistry registry) {
LocaleChangeInterceptor interceptor = new LocaleChangeInterceptor();
interceptor.setParamName("lng");
registry.addInterceptor(interceptor);
}
...