Internationalization in thymeleaf

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Internationalization in thymeleaf

Priya
we need to implement internationalization using spring and thymeleaf in our project.

As per our requirement , locale will be a user input. In thymeleaf according to the doc , we are using #{} text throughout. It works well with browser language support, but fails on using org.springframework.web.servlet.i18n.LocaleChangeInterceptor.


Following is the entry in dispatcher:
<bean id="viewResolver" class="org.thymeleaf.spring3.view.ThymeleafViewResolver">
                <property name="templateEngine" ref="templateEngine" />
                <property name="characterEncoding" value="UTF-8" />
        </bean>

        <bean id="messageSource"
                class="org.springframework.context.support.ResourceBundleMessageSource">
                <property name="basename" value="locale/messages" />
        </bean>
<bean id="localeChangeInterceptor"
                class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor">
                <property name="paramName" value="lang" />
        </bean>
<bean class="org.springframework.web.servlet.mvc.support.ControllerClassNameHandlerMapping" >
                <property name="interceptors">
                   <list>
                        <ref bean="localeChangeInterceptor" />
                    </list>
                </property>

we are passing 'lang' parameter in the url, yet it doesn't resolve it in accordance to that language. Property file for the same is also in place.

Please let us know the way forward.
Reply | Threaded
Open this post in threaded view
|

Re: Internationalization in thymeleaf

Zemi
Administrator
Hello,

we use non-standard locale resolver implementations and they work OK with Thymeleaf, but I guess that the problem is in the Spring configuration side.

Is the "locale" object as expected in your controllers?

Check the result of
   RequestContextUtils.getLocale(request);

Reply | Threaded
Open this post in threaded view
|

Re: Internationalization in thymeleaf

sunil0791
In reply to this post by Priya
Hi Priya

Zemi is right.

Try removing
<bean class="org.springframework.web.servlet.mvc.support.ControllerClassNameHandlerMapping" >
                <property name="interceptors">
                   <list>
                        <ref bean="localeChangeInterceptor" />
                    </list>
                </property>
</bean>

and add
<mvc:interceptors>
<bean id="localeChangeInterceptor"
                class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor">
                <property name="paramName" value="lang" />
        </bean>
</mcv:interceptors>
Reply | Threaded
Open this post in threaded view
|

Re: Internationalization in thymeleaf

Priya
Thanks a lot Sunil and Zemi!!
It's working!! :)