java - Spring i18n 不工作

标签 java spring-mvc internationalization context.xml

你好,我正在尝试在 Spring-MVC-Mavenconfigured-by-context.xml 项目中进行 i18n

我有文件(路径:\src\main\resources):

messages.properties

messages_pl.properties

当只有一个文件时,应用程序可以正常工作 -> 读取 < spring:messages ...> 就是这个人。 但是,当有 2 个文件时,应用程序仅读取 messages_pl.properties ,不关心 ?lang=en

DispatcherServlet-context.xml

/* [..] */
<mvc:annotation-driven enable-matrix-variables="true"/>
<mvc:resources  location="/resources/"  mapping="/resource/**"/>
<context:component-scan base-package="com.ehr" />

<mvc:interceptors>
    <bean class="com.ehr.webstore.interceptor.PerformanceMonitorInterceptor"/>
    <bean id="localeChangeInterceptor" class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor">
        <property name="paramName" value="lang"/>
    </bean>
</mvc:interceptors>
<bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource">
    <property name="basename" value="messages" />
    <property name="defaultEncoding" value="UTF-8"/>
</bean>
    <bean id="localeResolver" class="org.springframework.web.servlet.i18n.SessionLocaleResolver">
        <property name="defaultLocale" value="en"/>
    </bean>
/* [...] */

网页.jsp

< div class="pull-right" style="padding-right:50px">
    < a href="?lang=en" >en</a>|<a href="?lang=pl" >pl< /a>
< /div>

最佳答案

好的,我已经找到问题的根源了。总而言之,这是一个FallbackToSystemLocale属性默认设置为“true”。有关更多信息,请查看 ResourceBundleMessageSource 文档。

解决方案: 添加属性<property name="fallbackToSystemLocale" value="false"/><bean id="messageSource" [...] ResourceBundleMessageSource">

关于java - Spring i18n 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50348256/

相关文章:

java - 将 JMenuItem 添加到 JMenuBar 以在菜单中创建切换按钮

java - 自定义 Spring Security OAuth 2 响应

spring-mvc - DispatcherServlet 导致 java.lang.IllegalArgumentException : Servlet mapping specifies an unknown servlet name [default]

javascript - 在 spring mvc 中,如何获取 javascript var 作为 java 函数中的参数?

php - 使用多种自然语言的最有效方法

c++ - 在 NONCLIENTMETRICS 中,状态字体、消息字体和标题字体之间有什么区别?

javascript - 国际统计短信字符

java - "could not find or load main class "错误的原因是什么?

java - Spring - 是否有可能获取所有包,并在@ComponentScan 中注册?

java - 从 Velocity 模板获取占位符列表