繁体   English   中英

spring i18n在Windows和Linux之间的行为是不同的

[英]spring i18n behavior is different between Windows and Linux

我使用Spring boot i18n。

在Windows中,如果所选语言环境没有句子A,它将使用messages.properties中的句子。

在CentOS中,如果选择的语言环境没有句子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说:

如果给定的语言环境不是默认语言环境,则默认实现返回默认语言环境。

所以,我建议检查Java默认语言环境是否有所不同。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM