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

标签 spring internationalization locale interceptor

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

任何的想法?
谢谢

最佳答案

这就是我所做的:

  • 第一次复制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/>
    
  • 二手 #springMessages('message.title')在我的 *.vm

  • 就是这样。

    关于spring - Spring 和 Velocity 的 i18n(国际化)问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6413688/

    相关文章:

    python - 无法让 Django 本地化工作

    ubuntu - 在 docker 镜像中生成所有语言环境

    java - 如何在 Spring Boot 中将区域设置从 http 请求传递到 websocket?

    java - @Autowired 覆盖@Bean

    internationalization - 从 i18n 格式化字符串

    java - 在 Jetty 中生成用户线程

    iOS:多语言/多应用,应用商店会被拒绝吗?

    angular - Angular 7 中具有复数/选择属性的 i18n

    java - 当 @Scheduled 注解放置在轮询类内部时,Spring 任务执行器仅创建一个实例

    java - 使用Spring data Rest @RepositoryRestResource 创建rest端点时是否需要注释@EnableMongoRepositories