Thursday 9 May 2013

Spring MVC Internationalization

In Spring MVC application, comes with few “LocaleResolver” to support the internationalization or multiple languages features.


Properties file

welcome_en.properties

index.springmvc = hello eng

welcome_jp.properties

index.springmvc = hello Japan




Spring Configuration
To make Spring MVC application supports the internationalization, register two beans :

1. SessionLocaleResolver
Register a “SessionLocaleResolver” bean, named it exactly the same characters “localeResolver“. It resolves the locales by getting the predefined attribute from user’s session.

If you do not register any “localeResolver”, the default AcceptHeaderLocaleResolver will be used, which resolves the locale by checking the accept-language header in the HTTP request.

2. LocaleChangeInterceptor
Register a “LocaleChangeInterceptor” interceptor and reference it to any handler mapping that need to supports the multiple languages. The “paramName” is the parameter value that’s used to set the locale.

In this case,

index.htm?language=en – Get the message from English properties file.
index.htm?language=jp – Get the message from Japan properties file.

spring-servlet.xml



   
  
  
 
 
  
 
 
 
  
     
   
     
  
 

 
  
   
    /WEB-INF/resourcebundle/messages
   
  
  
  
 
 
   
index.jsp


0 comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...