小编Abh*_*yay的帖子

Spring Localization 无需在查询字符串中传递语言

我正在开发一个支持多种语言的 Web 应用程序项目。

我正在使用 Spring 框架。Spring 可以选择通过在调度程序 servlet 中添加以下 bean 来支持多语言。

<bean id="localeResolver"
        class="org.springframework.web.servlet.i18n.SessionLocaleResolver">
        <property name="defaultLocale" value="en" />
    </bean>

    <mvc:interceptors>
        <mvc:interceptor>
            <mvc:mapping path="/**" />
            <bean class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor">
                <property name="paramName" value="language" />
            </bean>
        </mvc:interceptor>
    </mvc:interceptors>

    <!-- Register the messages.properties -->
    <bean id="messageSource"
        class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
        <property name="basename" value="classpath:messages" />
        <property name="defaultEncoding" value="UTF-8" />
    </bean>
Run Code Online (Sandbox Code Playgroud)

只有当我在每个 URL 中传递语言参数时,本地化才有效。

是否有任何选项可以根据客户端的浏览器语言设置语言环境?

spring localization spring-mvc

2
推荐指数
1
解决办法
4085
查看次数

标签 统计

localization ×1

spring ×1

spring-mvc ×1