我使用 Spring boot i18n。
在windows下,如果选择的locale没有A句,就会使用messages.properties中的句子。
在CentOS中,如果选择的locale没有A句,会先使用messages_en_US.properties中的句子,如果messages_en也没有,则使用messages.properties中的句子。
为什么不一样?
@Bean
public LocaleResolver localeResolver() {
CookieLocaleResolver clr = new CookieLocaleResolver();//also can use SessionLocaleResolver
clr.setDefaultLocale(Locale.SIMPLIFIED_CHINESE);
return clr;
}
@Bean
public LocaleChangeInterceptor localeChangeInterceptor() {
LocaleChangeInterceptor lci = new LocaleChangeInterceptor();
lci.setParamName("locale");
return lci;
}
@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(localeChangeInterceptor());
}
最佳答案
我无法准确解释该行为,但可能是由 ResourceBundle.Control.getFallbackLocale
引起的. Javadoc 说:
The default implementation returns the default Locale if the given localeisn't the default one.
因此,我建议检查 Java 默认语言环境是否有所不同。
关于java - Windows 和 Linux 之间的 spring i18n 行为不同,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40799401/