我已经在 spring 配置中更改了默认语言环境,但是 spring 总是使用 messages_en.properties 而不是 messages.properties。看来 Spring 忽略了我对语言环境的选择。
定义的位置:
messages.properties
messages_en.properties
Spring 配置: application-context.xml
<bean id="localeResolver" class="org.springframework.web.servlet.i18n.SessionLocaleResolver">
<property name="defaultLocale" value="cs"/>
</bean>
<bean id="localeChangeInterceptor" class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor">
<property name="paramName" value="lang" />
</bean>
<bean name="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource">
<property name="basenames">
<list>
<value>messages</value>
</list>
</property>
<property name="defaultEncoding" value="UTF-8" />
</bean>
servlet-context.xml
<mvc:interceptors>
<mvc:interceptor>
<mvc:mapping path="/**" />
<exclude-mapping path="/admin/**"/>
<exclude-mapping path="/image/**"/>
<exclude-mapping path="/ajax/**"/>
<beans:bean class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor" />
</mvc:interceptor>
</mvc:interceptors>
在JSP页面中
<spring:message code="csn.terminology.csnId" />
<p>Current Locale : ${pageContext.response.locale}</p>
<!-- output is 'cs', but messages are from messages_en.properties file -->
项目中使用了Spring Framework 3.2.4 预先感谢您的帮助。
最佳答案
如果它是完整的配置那么你忘记添加语言环境解析器 您可以像这样添加一个 SessionLocaleResolver 并设置默认的语言环境属性
<bean id="localeResolver"
class="org.springframework.web.servlet.i18n.SessionLocaleResolver">
<property name="defaultLocale" value="en"></property>
</bean>
关于java - Spring 不使用默认语言环境中的源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18945978/