简体   繁体   English

Spring和Velocity的i18n(国际化)问题

[英]problem with i18n (internationalization) with Spring and Velocity

I am having a problem in setting up internationalization with Spring. 我在使用Spring设置国际化方面遇到问题。 Here is my config. 这是我的配置。

    <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 />

It always showing me English even when I request with ?locale=sv (Swedish). 即使我要求使用?locale=sv (瑞典语),它也总是向我显示英语。

I am using Spring with Velocity. 我正在使用Spring Velocity。

any idea? 任何的想法? thanks 谢谢

This is how I did: 这是我做的:

  • First copied messages_xx.properties in src/main/resources I could not get it to work with name messages_xx_xx (messages_en_us) 首先在src/main/resources复制了messages_xx.properties ,但我无法使它与名称messages_xx_xx (messages_en_us)一起使用

  • Then just added following configs to xxxx_servlet.xml context 然后只需将以下配置添加到xxxx_servlet.xml上下文中

     <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/>
  • Used #springMessages('message.title') in my *.vm 在我的*.vm使用了#springMessages('message.title')

that was it. 就是这样。

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

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