2014-10-27 48 views
0

我有一些问题处理我的web应用程序的国际化。 是否有可能通过Spring在MessageSource中找到消息,如果在其他消息中找不到消息?如何在2个消息包之间切换?

这是我的Spring配置

<bean id="messageSource" 
     class="org.springframework.context.support.ResourceBundleMessageSource"> 
     <property name="basename" value="xxMessage" /> 
    </bean> 

    <bean id="localeResolver" 
     class="org.springframework.web.servlet.i18n.SessionLocaleResolver"> 
     <property name="defaultLocale" value="en" /> 
    </bean> 

举例:如果 关键是“login.user”和区域设置为“EN”的应用会显示在我的xx_en.properties的值,如果存在,但我如果该键不存在,则要在其他文件(xx_es.properties)中进行搜索。 这可能吗?

P.S:对不起,我的英语:D

在此先感谢!

回答

0

我认为你需要在你的Spring配置拦截器配置

<interceptors> 
    <beans:bean 
     class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor"> 
     <beans:property name="paramName" value="locale" /> 
    </beans:bean> 
</interceptors> 
0

谢谢您的回答@DDK我已经设法解决这个问题:d以下

解决方案。

定义链接消息源,由接口HierarchicalMessageSource提供。

举例来说,如果你有你的i18n文件 baseMessages.properties 和 messages.properties

,你可以把它们连为

<bean id="baseMessageSource" class="org.springframework.context.support.ResourceBundleMessageSource"> 
    <property name="basename" value="baseMessages" /> 
</bean> 
<bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource"> 
    <property name="basename" value="messages" /> 
    <property name="parentMessageSource" ref="baseMessageSource" /> 
</bean>