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

发布于 2024-11-16 10:16:27 字数 805 浏览 7 评论 0原文

我在使用 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。

有什么想法吗? 谢谢

I am having a problem in setting up internationalization with 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).

I am using Spring with Velocity.

any idea?
thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

分开我的手 2024-11-23 10:16:27

这就是我的做法:

  • 首先在 src/main/resources 中复制 messages_xx.properties
    我无法让它使用名称 messages_xx_xx (messages_en_us)

  • 然后将以下配置添加到 xxxx_servlet.xml 上下文

    
            <属性名称=“基本名称”值=“类路径:消息”/>
            <属性名称=“defaultEncoding”值=“UTF-8”/>
    
    
    <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')

就是这样。

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)

  • 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/>
  • Used #springMessages('message.title') in my *.vm

that was it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文