【问题标题】:problem with i18n (internationalization) with Spring and VelocitySpring 和 Velocity 的 i18n(国际化)问题
【发布时间】:2011-06-20 15:30:17
【问题描述】:

我在使用 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(瑞典语)提出请求,它也总是向我显示英语。

我正在使用带有 Velocity 的 Spring。

有什么想法吗? 谢谢

【问题讨论】:

    标签: spring internationalization locale interceptor


    【解决方案1】:

    我就是这样做的:

    • 首先复制messages_xx.propertiessrc/main/resources 我无法使用名称 messages_xx_xx (messages_en_us)

    • 然后将以下配置添加到 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/>
    
    • 在我的*.vm 中使用#springMessages('message.title')

    就是这样。

    【讨论】:

      最近更新 更多