Spring 3 MVC: Internationalization & Localization Tutorial with Example

Welcome to Part 5 for Spring 3.0 MVC Series. In previous article we saw how to configure Tiles framework with Spring 3 MVC application. We used org.springframework.web.servlet.view.tiles2.TilesConfigurer class in bean definition to define the tiles configuration file. This divided our HelloWorld Spring MVC application in sections such as header, footer etc.

In this part we will discuss about Internationalization (I18N) and Localization (L10N) in Spring 3.0 MVC. We will add i18n support followed by l10n to our HelloWorld Spring application that we created in previous tutorials in this series. I strongly recommend you to go through previous articles and download the source code of our sample application.

What is i18n and L10n?

In computing, internationalization and localization are means of adapting computer software to different languages and regional differences. Internationalization is the process of designing a software application so that it can be adapted to various languages and regions without engineering changes. Localization is the process of adapting internationalized software for a specific region or language by adding locale-specific components and translating text.

The terms are frequently abbreviated to the numeronyms i18n (where 18 stands for the number of letters between the first i and last n in internationalization) and L10n respectively, due to the length of the words. The capital L in L10n helps to distinguish it from the lowercase i in i18n.

Our Goal

Our goal is to add Internationalization and Localization support to our Spring MVC application. Once finished our app will look like.

We will add two languages support to our application: English and German. Depending on the locale setting of users browser, the appropriate language will be selected. Also user will be able to select the language from top-right corner of the application.

Message Resouces File

We will create two properties file which will contain all the messages to be displayed in the application. These files are kept in a source folder called “resources”. Create a source folder in your project by Right click on Project name > New > Source Folder and name it resources.

Create two files messages_en.properties and messages_de.properties in this folder and copy following content into it.

File: resources/messages_en.properties

label.firstname=First Name
label.lastname=Last Name
label.addcontact=Add Contact

label.title=Contact Manager

label.footer=© ViralPatel.net

File: resources/messages_de.properties

label.addcontact=Addieren Kontakt 

label.title=Kontakt Manager

label.footer=© ViralPatel.net

Configuring Internationalization (i18n) / Localization (L10n) in Spring MVC

Now we have created message resource properties for our application. We need to declare these files in spring configuration file. We will use class org.springframework.context.support.ReloadableResourceBundleMessageSource to define the message resources.

Also, note that we will provide a feature where user will be able to select language for the application. This is implemented by using org.springframework.web.servlet.i18n.LocaleChangeInterceptor class. The LocaleChangeInterceptor class will intercept any changes in the locale. These changes are then saved in cookies for future request. org.springframework.web.servlet.i18n.CookieLocaleResolver class will be used to store the locale changes in cookies.

Add following code in the spring-servlet.xml file.


	<bean id="messageSource"
		<property name="basename" value="classpath:messages" />
		<property name="defaultEncoding" value="UTF-8"/>

	<bean id="localeChangeInterceptor"
		<property name="paramName" value="lang" />

	<bean id="localeResolver"
		<property name="defaultLocale" value="en"/>

	<bean id="handlerMapping"
		<property name="interceptors">
			<ref bean="localeChangeInterceptor" />

Note that in above configuration we have defined basename property in messageSource bean to classpath:messages. By this, spring will identify that the message resource message_ will be used in this application.

Change the View – The JSPs

Now as we have created two message resources files and configured it in Spring MVC, we will use these messages in the JSP files. Open all the JSP files of our demo application and update with following code.


<%@taglib uri="http://www.springframework.org/tags" prefix="spring"%>

<h3><spring:message code="label.title"/></h3>

<span style="float: right">
	<a href="?lang=en">en</a> 
	<a href="?lang=de">de</a>


<%@taglib uri="http://www.springframework.org/tags" prefix="spring"%>

<p><spring:message code="label.menu"/></p>


<%@taglib uri="http://www.springframework.org/tags" prefix="spring"%>

<spring:message code="label.footer"/>


<%@taglib uri="http://www.springframework.org/tags" prefix="spring"%>
<%@taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
	<title>Spring 3 MVC Series - Contact Manager</title>

<form:form method="post" action="addContact.html">

		<td><form:label path="firstname"><spring:message code="label.firstname"/></form:label></td>
		<td><form:input path="firstname" /></td> 
		<td><form:label path="lastname"><spring:message code="label.lastname"/></form:label></td>
		<td><form:input path="lastname" /></td>
		<td><form:label path="lastname"><spring:message code="label.email"/></form:label></td>
		<td><form:input path="email" /></td>
		<td><form:label path="lastname"><spring:message code="label.telephone"/></form:label></td>
		<td><form:input path="telephone" /></td>
		<td colspan="2">
			<input type="submit" value="<spring:message code="label.addcontact"/>"/>

Note that in above JSP, we used <spring:message> tag to display the message from resource bundle.

One thing that we must note here is that in header.jsp file, we have specified two links to select language. The link sets a request parameter ?lang= when user click on this link. Note that spring identifies this request parameter by using LocaleChangeInterceptor interceptor and change the local accordingly. Also note that while configuring LocaleChangeInterceptor in spring-servlet.xml file, we have specified property “paramName” with value “lang”

<property name="paramName" value="lang" />

Thus the Spring framework will look for a parameter called “lang” from request.

That’s All Folks

That’s pretty much it :) We just added Internationalization and Localization support to our demo Spring 3.0 MVC application. All you have to do is just execute the app in Eclipse. Press Alt + Shift + X, R.



Download Source Code

Click here to download Source Code (10.2kb)

Moving On

Today we saw how to add Internationalization i18n and Localization L10n support to Spring 3.0 based web application. We used LocaleChangeInterceptor to intercept the change in locale and ReloadableResourceBundleMessageSource class to add message resources properties. In the next part we will discuss Themes in Spring MVC and how to implement it. I hope you liked this article. Feel free to post your queries and comments in comment section.

Get our Articles via Email. Enter your email address.

You may also like...


  1. mateusz f says:

    I have a queston. You defined two languages, and de. What if a visitor comes who is from let’s say Canada. Which locale will be chosen for him as default? Is there a way to specify a default locale at all?

    • Viral Patel says:

      @mateusz f. nice question. There is a way in spring to define default local. This can be done by passing parameter defaultLocale to CookieLocaleResolver bean.

      <bean id="localeResolver"
      	<property name="defaultLocale" value="en"/>
  2. Jim says:

    Thank you for your blog, much appreciated.

  3. Jim says:

    Thanks very much for the sample.

    Only question so far is that when I run mvn tomcat:redeploy it looks for mvc-basic-1.0.0-SNAPSHOT.war rather than mvc-basic.war that the install actually builds

  4. Gerlad says:

    Please SWF tutorial! Great Job

  5. Ajit says:

    gr8 job done
    Can you show security cache in spring 3

  6. Luponiano says:

    Hi Viral, nice tutorial.
    I am experiencing problems. I have followed your example and used two languajes, spanish and english. If I set the defaultLocale to ‘en’ all the page is visible on english no matter the spanish accept of the navigator. It is as if it setted how the page should be viewed as default unless the user specifies something different. Do you know if it can be used so the page is viewed in spanish if the navigator is set to spanish and to english otherwise?
    Setting the defaultLocale solved the problem of other navigators with another languaje setted.


  7. Luponiano says:

    Hi Viral, I finally managed to solve the problem by extending the SessionLocaleResolver, overriding the determineDefaultLocale and injecting the supported languajes to the new resolver. It may sound a little complicated but it was not too much and now works like a charm.

    Thank you for the basis.

    • L Lobo says:

      Hi Can you please post your code…

  8. saravanan says:

    it is very nice website for spring, it is very useful to me.

  9. Bharath says:

    Thanks for your tutorial…. its really helpful…..

  10. Kiran Hegde says:

    Hi Viral, good work man…
    Latest tech stuff…

  11. Alex says:

    Great tutorial, finally I’m making some stuff with spring, thanks man.

  12. damiencharp says:

    Thanks ! Keep up the good work.

  13. amila says:

    place can u give another tutorial in netbeans

  14. amila says:

    if u can give me same ref:
    thank u

  15. Gal Levisnky says:

    Very nice introduction, however it is possible to make it even with less config:
    remove the handlerMapping from the xml, and replace the LocaleChangeInterceptor with the following:

    than in the header user ?locale=de instead of ?lang=de.


  16. sai says:

    hi Luponiano

    can u post ur session local resolver example?

    thanks much

  17. Hriday says:

    Thanks very much … it was really helpful. But I stuck in problem. In case I already have a parameter in my url in tht case ?lang=en breaks
    eg. I hv a url
    Now if click on lang English, it will append the ?lang=en to it which is creating problem. Can you suggest some solution to this.

    Thanks Again

  18. VK says:

    Nice work man.. really appreciate this… helped me to quickly learn the basics of spring.

  19. Falkster says:

    Great stuff. Thanks a lot!


    There are two little mistakes in the German translations. It’s „Kontakt-Manager“ not „Kontakt Manager“, the hyphen is obligatory on compounds (you could also translate it fully into german and write it as one word: „Kontaktverwaltung“). And you can’t say/write „Addieren Kontakt“. „Kontakt addieren“ would be O.K., but „addieren“ is commonly related to a mathematical context, so „Kontakt hinzufügen“ would be much better.

  20. Hitesh Joshi says:

    Nice Tutorial Viral. Have a question though related to the following:

    In the above, the messages.properties and related files need to be present in the classpath of the application. Can I give a relative path with respect to the classpath? Basically, my problem is that I have all my messages.properties related files in the JBoss Server config location and not in the created WAR file. So, how should I configure the messageSource Bean.


  21. Diman says:

    Hi Viral,
    thanks a lot for example. Localisation in the context of your tutorials means, user has to tell us where he comes from(or what language he/she speaks), right? Is there any way in spring, to check where he comes from… also to be able to give user a suggestion of his language. Example, if user accessing my webpage from chinese (or russian) server… Maybe I can already display contact form in chinese (or in russian).

    Thanks and Best Regards,

  22. suma says:


    I have implemented localization the same way you have described.
    I am getting an exception
    ERROR 2011-02-25 12:27:01,448 [http-8080-1] org.springframework.web.servlet.tags
    .MessageTag: No message found under code ‘title.xxx’ for locale ‘en_US’.
    javax.servlet.jsp.JspTagException: No message found under code ‘title.xxx
    for locale ‘en_US’.

    Any ideas

    • Viral Patel says:

      Hi Suma, Check your JSPs and see if you are using any message key “title.xxx”? I think there is a mismatch in the values defined in message resource properties and the JSPs.

  23. ricky says:

    Hi Suma, I had the same issue. Just make sure you create the ‘resources’ folder as a ‘Source Folder’ as Viral indicated. If you create the ‘resources’ folder as a ‘Folder’ the 2 messages property files does not get copy to your war file.

    • Ruchi says:

      Thanks for your suggestion. I was getting the same issue which suma was getting and your suggestion has resolved my issue. But please let me know what is the difference between folder and source folder.

  24. Sandeep Tyagi says:

    Very nice, and precisely build example. keep it up guys.

  25. Borpf says:

    hmm.. ok this tutorial can be used for internationalisation, but it just describes a way to replace some text by submitting a request parameter. Real locale switching would matter in different outputs e.g. on DateFormats like en=01/31/1970 de=31.01.1970 or currency outputs.. How about extending this example to show, that switching locale by using LocaleChangeInterceptor and LocaleResolver would also effect these points?

  26. Goutham says:

    Hi , nice tutorial,However i have a prob here. Clicking on the en|de i am not getting tge diff locale..
    I have added the following in my own xml:

    And my messages.properties are in place for both the languages.
    And my header has the following :
    en |
    de |

  27. Goutham says:

    My ?lang=de as well as ?lang=en is displaying the same text even though text in both the properties is different. I am not able to change my local. I ve added this my XML :

  28. Sara says:

    In case you’re using Spring 3.0.5, please be aware of the conflict between and DefaultAnnotationHandlerMapping (http://forum.springsource.org/showthread.php?81238-Conflict-between-lt-mvc-annotation-driven-gt-and-DefaultAnnotationHandlerMapping).
    I.e.instead of defining the interceptor by creating, as in the example, the bean localeChangeInterceptor and then putting it in bean handlerMapping, you would just need to define it inside the tag, like this:

    • Kiran says:

      Hi I am getting error saying
      No context loader listner found

  29. Bolat says:

    Dear Viral,

    Unfortunately, the necessary amended spring-servlet.xml definition for Spring 3.0.5 by Sara (last comment) did not come out (as it appears that xml tags are automatically omitted when posting). Would you happen to know how to define it inside the tag as there is a conflict when using the standard spring-servlet.xml file for Spring 3.0.5, which includes the xmlns:mvc=”http://www.springframework.org/schema/mvc tag in the header, which thereby enforces the declaration of the mvc:annotation-driven tag.

    Many thanks.

    Kind regards,

  30. Bolat says:

    Dear Viral,

    Just to be clear regarding my post a few minutes ago, if I remove the xmlns:mvc=”http://www.springframework.org/schema/mvc tag in the header and also the mvc:annotation-driven tag, the language switching from English to German works very well, but I prefer to have these tags as they recommended in the latest release of Spring, which is 3.0.5. The strange thing is, that with these tags, it reads the messages_en.properties file and naturally displays the form in English, but does not do the switching to German upon clicking ‘de’, it remains as English.

    Any help or directions will be most appreciated.

    Many thanks,

  31. Bolat says:

    Dear Viral,

    I have one Final question and would appreciate a reply: I noticed that you have put HTML decimal ü to display the dotted u. Is there way of doing this directly by Typing the actual letter in the editor instead of giving numerical codes, especial for the dotless i (code ı) as when I put the dotless i directly (via Notepad using Windows 7 language for Tukish, mapped to keyboard key I), upon running the application, it comes out as ‘?’.

    Many thanks.

    Kind regards,

  32. Bolat says:

    REVISED: Dear Viral,

    I have one Final & quick question and would really appreciate a reply: I noticed that you have put the html decimal code 252 to display the dotted u / ü. Is there way of doing this directly without Typing the the codes, but rather type the actual letters in the Editor, especial for the Turkish dotless i / ı letter (html decimal code 305) as when I put the dotless i directly via an Editor using Windows 7 language for Turkish (mapped to keyboard key letter i), it comes out as ‘?’ when running this tutorial on the browser. This is IMPORTANT as I may have lots of translations to do and to put html decimal codes for each special character opens up room for potential errors and of course it is very time consuming. Any guidance on this matter will be much appreciated.

    Many thanks.

    Kind regards,

    • Vandana says:

      Hello Bolat, Since you have faced the same reply as me, and the solution is not clear from Sara’s or our post, can you please share the same. Problem is the same: using stops the locale change functionality. And I do need to use the mvc annotation, fr the Ajax to work.

  33. CAD says:

    Great article, i have a question, Anyone know if can i access to messages with an expression like $message[‘code’] or something similar instead use spring:message tag?


  34. rojanu says:

    @Bolat properties files can only be in ASCII therefore any character thats is not ASCII must presented in \u notation. native2ascii, which comes with java, used to convert the file e.g. “native2ascii -encoding utf-8 input.txt messages_tr.properties”

  35. ram says:

    Its really very useful. I really appreciate it. Thanks folks.

  36. Kamil says:

    Thanks, very useful. Do you have idea how to setup language switch in url like
    http://domain/en/…. (english)
    http://domain/… (english)
    http://fomain/de/… (german)
    so that website in english can be indexed by google bots

  37. isha says:

    I’m not getting different language when I’m clicking on the link “de”.
    Even When I’m using by default other than english same ,english language is only coming…
    Can anyone help me to know what misake I’m doing…….????

  38. laff81 says:

    Doesn’t work?


    bean id=”localeChangeInterceptor”
    property name=”paramName” value=”lang” /

    And remove the bean “handlerMapping”.

  39. Kam says:

    Excellent tutorial. If you are working in IDE and not bothered about deployment, make sure that you declare your resource folder as Source folder so that the messages*.properties files are automatically deployed in /WEB-INF/classes folder.

  40. Krzysztof Blaszke says:

    Hi! Thak You for great tutorial! :-)
    I had to add:

    to my servlet-context.xml to applikaction work.
    Best regards


  41. Kelvin says:

    javax.servlet.jsp.JspTagException: No message found under code ‘label.title’ for locale ‘en’.

  42. Tullio says:

    After different experiments I defined my messageSource bean like this and it worked:


  43. Tullio says:

    After different experiments I defined my messageSource bean like this and it worked:
    beans:bean id=”messageSource” class=”org.springframework.context.support.ReloadableResourceBundleMessageSource”
    beans:property name=”basenames”
    beans:property name=”defaultEncoding” value=”ISO-8859-1″ /
    beans:property name=”cacheSeconds” value=”1″ /

    Sorry about the format…

  44. Tharindu says:

    How to stop it from going to RequestMapped method. Because I tried, and it was taken by the Controller method when I tried to change the language. Although lang request parameter is there, as it is coming from a URL which mapped to a RequestMapping in Controller class, it does not give me the intended result. Am I missing a piece of puzzle here? :(

  45. Dorley Pan says:

    I added chinese characters to the example (messages_zh.properties), but my chinese characters are not displayed properly (instead of actual characters there were shown as ?).

    I tested by reverting to not using tiles2 and it will display the chinese characters correctly. How can chinese characters works with tiles2 ?

  46. lakshmi says:

    i need code without using those links en & de. Because in system itself we can select lang.. which we want.

  47. Kandhi says:

    I need the locale checking in js , ie I need to check the locale in document on ready for setting the message .But I couldn’t get the locale in js .
    I used above method and my jsp is:


    this is working fine .

    But in that pages a message came from document onload function , so i need to check the code

  48. Japan Trivedi says:


    Thanks for the nice tutorial. But I have a problem while doing the same configuration using spring framework 3.1 without any xml.

    I have created one application that uses no xml files for the web application using Spring Framework 3.1. I have done the above mentioned configuration for Internationalization in a java file that works exactly same way spring-servlet.xml works.

    But I am not able to successfully implement internationalization.

    Have you tried this??

    Do you have any solution in this context.


  49. Larry says:

    Thanks for the tutorial – having an issue though (XML configuration is obviously not my string suit, and frankly driving me a little nuts).

    I’ve placed my messages_en_US.properties file in ./src/main/webapp/resources/international, but haven’t found a way to resolve the location. Every time it runs, it’s throwing an error “Can’t find bundle for base name messages, locale en_US”, no matter how I prefix the location in the bean. I would have thought the mapping for /resources/ would have handled this, but if so, I’m stuck.

    Secondary issue is that the “defaultEncoding” property name in messageSource bean fails with “No setter found for property ‘defaultEncoding'”. Less critical, but would like to know what’s up with that, too.

    Running STS 2.9.1.RELEASE and using SpringFramework 3.1.0.RELEASE.

    Hoping one of the brilliant developers who read this can help. Here’s my WEB-INF/spring/appServlet/servlet-context.xml file:

    <!– –>

    • Nhat Dinh Van says:

      Yeah! final i can do it.

  50. Amit says:

    Thanks for the tutorial …

    I’m using Spring 3.1.0 and configured in the same way but it is always taking value from default locale

Leave a Reply

Your email address will not be published. Required fields are marked *