使用Spring和Velocity进行国际化(i18n)时出现问题

4

我在使用Spring进行国际化设置时遇到了问题,以下是我的配置。

    <bean id="messageSource"
            class="org.springframework.context.support.ResourceBundleMessageSource">
            <property name="basename" value="localization" />
    </bean>
    <!-- declare the resolver -->
    <bean id="localeResolver"
            class="org.springframework.web.servlet.i18n.CookieLocaleResolver">
            <property name="defaultLocale" value="sv" />
    </bean>
    <mvc:interceptors>
            <bean class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor" />
    </mvc:interceptors>
    <mvc:annotation-driven />

当我使用?locale=sv(瑞典语)请求时,它总是显示英语。

我正在使用Spring和Velocity。

有什么想法吗? 谢谢。

1个回答

2

这是我做的方法:

  • First copied messages_xx.properties in src/main/resources I could not get it to work with name messages_xx_xx (messages_en_us)

  • Then just added following configs to xxxx_servlet.xml context

    <bean id="messageSource"
            class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
            <property name="basename" value="classpath:messages" />
            <property name="defaultEncoding" value="UTF-8" />
    </bean>
    

    <mvc:interceptors>
    <bean id="localeChangeInterceptor"
        class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor">
        <property name="paramName" value="lang"/>
    </bean>
    </mvc:interceptors>

    <mvc:annotation-driven/>
  • 我在我的*.vm中使用了#springMessages('message.title')

就是这样。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接