Most of the spring framework supports internationalization, just like SPRINGMVC. Dispatcherservlet enables you to dynamically configure in the local language of the client. This is done through the localeresolver.
When a request arrives, Dispatcherservlet will look for Localeresolver and will attempt to localize it if found. Using the Requestcontext.getlocale () method we can get the localized language of locale resolver interpretation.
Locale resolvers and interceptors are defined in the org.springframework.web.servlet.i18n package and can be configured in application context. Here is the configuration section of the localization parser.
First, Acceptheaderlocaleresolver
The locale resolvers is parsed based on the Accept-language request header information, which typically contains the local indication of the client's operational information.
Second, Cookielocaleresolver
This parser uses cookies to find client-specific language information. If found, this configuration is used. Using some of the properties of this locale resolvers, we can specify the name of the cookie or even the maximum time to live. Here is a configuration instance:
e.g.
[HTML]View Plaincopy
- <Bean id= "localeresolver" class=" Org.springframework.web.servlet.i18n.CookieLocaleResolver ">
- <property name= "cookiename" value="ClientLanguage"/>
- <!--in seconds. If set To-1, the cookie isn't persisted (deleted when browser shuts down) --
- <property name= "cookiemaxage" value="100000">
- </Bean>
The following is a list of cookielocaleresolver properties
Property Default Description
CookieName classname+local The name of the cookie
Cookiemaxage Integer.max_int Max Survival time
Cookiepath/Restrict the path to the program that can access the cookie.
Third, Sessionlocaleresolver
This parser allows you to parse the local settings through the session.
Iv. Localechangeinterceptor
By configuring Localechangeinterceptor, we can dynamically change the local language. It detects the parameters in the request and changes the region information. It calls Loacalresolver.setlocal () to configure. The following example shows that calling all *.view resources contains a variable named Sitelanguage to change the region information. So the following url:http://www.sf.net/home.view?sitelanguage=nl will change the site language to Dutch.
e.g.
[HTML]View Plaincopy
- <Bean id="Localechangeinterceptor"
- class="Org.springframework.web.servlet.i18n.LocaleChangeInterceptor">
- <property name= "paramname" value="sitelanguage"/>
- </Bean>
- <Bean id="Localeresolver"
- class="org.springframework.web.servlet.i18n.CookieLocaleResolver"/>
- <Bean id="urlmapping"
- class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
- <property name="interceptors">
- <list>
- <ref bean="Localechangeinterceptor"/>
- </list>
- </Property>
- <property name="mappings">
- <value>/**/*. view=somecontroller</value>
- </Property>
- </Bean>
Localization and internationalization of SPRINGMVC