I am working on a web application that uses the Spring Framework, Spring (MVC), Spring Security, etc ... Spring's documentation shows internationalization adding a parameter to the url (like http://myexample.com?lang = fr ) But I read this article by Google Multiregional and multilingual sites , which says that this practice is not recommended.
So I decided to implement it like this:
http://myexample.com/ โ default locale (EN)
http://myexample.com/es/ โ locale es
http://myexample.com/fr/ โ locale fr
My question is: what is the best way to implement i18n (subdirectories with gTLD) within Spring? Ideas, articles, examples are welcome.
<!-- Defines interceptors for Locale change and Theme change before the request goes to DispatcherServlet for further operation. --> <mvc:interceptors> <ref bean="localeChangeInterceptor"/> <ref bean="themeChangeInterceptor" /> <!-- <ref bean="conversionServiceExposingInterceptor"/> --> </mvc:interceptors> <!-- Interceptor for change in Locale --> <bean id="localeChangeInterceptor" class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor"> <property name="paramName" value="language"/> </bean> <!-- LocaleResolver configuration for internationalization. Here cookie resolver used. Stores and reads the locale value from cookie. --> <bean id="localeResolver" class="org.springframework.web.servlet.i18n.CookieLocaleResolver"> <property name="defaultLocale" value="1"/> <property name="cookiePath" value="/WEBPORTAL/" /> <property name="cookieName" value="locale"/> <property name="cookieMaxAge" value="86400"/> <property name="cookieHttpOnly" value="true"/> <property name="cookieSecure" value="true"/> </bean> <!-- Provides the list of base location for Localized property files. Default encoding must be UTF-8 to support multilingual text. --> <bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource"> <property name="basenames"> <list> <value>/WEB-INF/i18n/labels</value> <value>/WEB-INF/i18n/messages</value> <value>/WEB-INF/i18n/mailBox</value> <value>/project</value> </list> </property> <property name="defaultEncoding" value="UTF-8"/> </bean>
Here is some code that will help you achieve internationalization. You just need to add these lines of code to the dispatcher-servlet.xml file and make changes according to your requisites.
Hope my answer guides you ...