<div dir="ltr" style="text-align: justify;">
<p>In this chapter we will discuss about Internationalization (I18N) and Localization (L10N) in Spring 3.0 MVC.</p>
<p><i><b>What is i18n and L10n?</b></i><br />
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.</p>
<p>The terms are frequently abbreviated to the numerous 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.</p>
<div style="background-color: #f2f9fc; border: 1px solid #c9e6f2; border-radius: 3px; padding: 16px; line-height: 1.45;"><span style="color: red; font-size: x-large; text-align: center;"><b>Popular Tutorials</b></span></p>
<ul style="text-align: left;">
<li><b><a href="https://dineshonjava.com/spring-tutorial/"><em><strong>Spring Tutorial</strong> </em></a></b></li>
<li><b><a href="https://dineshonjava.com/spring-web-mvc-framework-chapter-38/"><strong><em>Spring MVC Web Tutorial </em></strong></a></b></li>
<li><b><a href="https://dineshonjava.com/introduction-to-spring-boot-a-spring-boot-complete-guide/"><strong>Spring Boot Tutorial</strong> </a></b></li>
<li><b><a href="https://dineshonjava.com/spring-security-take-baby-step-to-secure/"><em>Spring Security Tutorial</em></a></b></li>
<li><b><a href="https://dineshonjava.com/spring-aop-tutorial-with-example-aspect-advice-pointcut-joinpoint/"><em>Spring AOP Tutorial</em></a></b></li>
<li><b><a href="https://dineshonjava.com/using-spring-jdbc-framework-chapter-32/"><em>Spring JDBC Tutorial</em></a></b></li>
<li><b><a href="https://dineshonjava.com/spring-hateoas-hypermedia-driven-restful-web-service/"><em><strong>Spring HATEOAS </strong></em></a></b></li>
<li><b><a href="https://dineshonjava.com/microservices-with-spring-boot/"><em><strong>Microservices with Spring Boot</strong></em></a></b></li>
<li><b><a href="https://dineshonjava.com/jax-rs-web-service-tutorial/"><strong><em>REST Webservice</em> </strong></a></b></li>
<li><b><a href="https://dineshonjava.com/core-java-baby-step-to-be-best-java-ian/"><em><strong>Core Java </strong></em></a></b></li>
<li><b><a href="https://dineshonjava.com/hibernate-3-on-baby-steps/"><em><strong>Hibernate Tutorial</strong></em></a></b></li>
<li><b><a href="https://dineshonjava.com/spring-batch-process-with-example/"><strong><em>Spring Batch</em> </strong></a></b></li>
</ul>
</div>
<p>Now lets we create an application which support multiple languages. We will add two languages support to our application: <b>English </b>and <b>German</b>. Depending on the locale setting of users browser, the appropriate language will be selected.</p>
<p><i><b>Step 1:</b></i> First we create the properties file for the different languages.</p>
<ol>
<li>messages_en.properties</li>
<li>messages_de.properties</li>
</ol>
<div id="ads-id" align="center"></div>
<p><b>resources/messages_en.properties</b></p>
<pre class="highlight">emp.label.id=Employee Id 
emp.label.name=Employee Name 
emp.label.age=Employee Age 
emp.label.salary=Salary 
emp.label.address=Address 
 
label.menu=Menu 
label.title=Employee Management System 
 
label.footer=© dineshonjava.com 
</pre>
<p><b>resources/messages_de.properties</b></p>
<pre class="highlight">emp.label.id=Impelyee Id 
emp.label.name=Impelyee Vorname 
emp.label.age=Impelyee iage 
emp.label.salary=shalery 
emp.label.address=Adrrezz 
 
label.menu=Menü 
label.title=Impelyee Managemenot Sistom 
 
label.footer=© dineshonjava.com 
</pre>
<p><i><b>Step 2: Configure i18n &; l10n to Spring3MVC</b></i><br />
we need to declare these files in spring configuration file. We will use class <i><b>org.springframework.context.support.ReloadableResourceBundleMessageSource</b></i> 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 <i><b>org.springframework.web.servlet.i18n.LocaleChangeInterceptor</b></i> class. The LocaleChangeInterceptor class will intercept any changes in the locale. These changes are then saved in cookies for future request. <i><b>org.springframework.web.servlet.i18n.CookieLocaleResolver</b></i>class will be used to store the locale changes in cookies.<br />
Add following code in the <i><b>sdnext-servlet.xml</b></i> file.</p>
<pre class="highlight"><;bean class="org.springframework.context.support.ReloadableResourceBundleMessageSource" id="messageSource">; 
 <;property name="basename" value="classpath:messages">;<;/property>; 
 <;property name="defaultEncoding" value="UTF-8">;<;/property>; 
<;/bean>; 
 
<;bean class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor" id="localeChangeInterceptor">; 
 <;property name="paramName" value="lang">;<;/property>; 
<;/bean>; 
 
<;bean class="org.springframework.web.servlet.i18n.CookieLocaleResolver" id="localeResolver">; 
 <;property name="defaultLocale" value="en">;<;/property>; 
<;/bean>; 
 
<;bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping" id="handlerMapping">; 
 <;property name="interceptors">; 
 <;ref bean="localeChangeInterceptor">;<;/ref>; 
 <;/property>; 
<;/bean>; 
</pre>
<p><b>Note </b>that in above configuration we have defined basename property in <i><b>messageSource </b></i>bean to <i><b>classpath:messages</b></i>. By this, spring will identify that the message resource <i><b>message_ </b></i>will be used in this application.<br />
Change in the JSPs Template:<br />
WebRoot/WEB-INF/views/header.jsp</p>
<pre class="highlight"><;%@taglib uri="http://www.springframework.org/tags" prefix="spring"%>;</pre>
<h3><;spring:message code=&#8221;emp.label.title&#8221;>;<;/spring:message>;</h3>
<p><;span style=&#8221;float: right;&#8221;>; <;a href=&#8221;?lang=en&#8221;>;en<;/a>; | <;a href=&#8221;?lang=de&#8221;>;de<;/a>; <;/span>;</p>
<p>WebContent/WEB-INF/views/menu.jsp</p>
<pre class="highlight"><;%@taglib uri="http://www.springframework.org/tags" prefix="spring"%>; 
 
<;spring:message code="emp.label.menu">;<;/spring:message>;</pre>
<p> ;</p>
</div>
<div style="background-color: #f2f9fc; border: 1px solid #c9e6f2; border-radius: 3px; padding: 16px; line-height: 1.45;"><span style="color: red; font-size: x-large; text-align: center;"><b>Spring MVC Related Posts</b></span></p>
<ul>
<li><b><a href="https://dineshonjava.com/spring-web-mvc-framework-chapter-38/"><span style="color: red;">Spring MVC Web Tutorial</span></a></b></li>
<li><b><a href="https://dineshonjava.com/spring-mvc-interview-questions-and-answers/"><span style="color: red;">Spring MVC Interview Questions</span></a></b></li>
<li><b><a href="https://dineshonjava.com/introduction-to-mvc/"><span style="color: red;">MVC Design Pattern</span></a></b></li>
<li><b><a href="https://dineshonjava.com/what-is-dispatcherservlet-in-spring-and-its-uses/"><span style="color: red;">Spring MVC DispatcherServlet </span></a></b></li>
<li><b><a href="https://dineshonjava.com/difference-between-applicationcontext-webapplicationcontext-in-spring-mvc/"><span style="color: red;">Spring MVC WebApplicationContext and Root Application Context</span></a></b></li>
<li><b><a href="https://dineshonjava.com/stereotype-annotations-in-spring/"><span style="color: red;">Spring MVC @Controller Annotation</span></a></b></li>
<li><b><a href="https://dineshonjava.com/requestmapping-annotation-in-spring-mvc/"><span style="color: red;">Spring MVC @RequestMapping Annotation</span></a></b></li>
<li><b><a href="https://dineshonjava.com/requestparam-annotation-in-spring-mvc-with-example/"><span style="color: red;">Spring MVC @RequestParam Annotation</span></a></b></li>
<li><b><a href="https://dineshonjava.com/difference-between-applicationcontext-webapplicationcontext-in-spring-mvc/"><span style="color: red;">Spring MVC ContextLoaderListener</span></a></b></li>
<li><b><a href="https://dineshonjava.com/requestparam-vs-pathvariable-annotations-in-spring-mvc/"><span style="color: red;">Spring MVC @RequestParam and @PathVariable annotations</span></a></b></li>
<li><b><a href="https://dineshonjava.com/spring-30-mvc-hello-world-example/"><span style="color: red;">Spring MVC Hello World Example</span></a></b></li>
<li><b><a href="https://dineshonjava.com/spring-exception-handling-example/"><span style="color: red;">Spring MVC Exception Handling Example</span></a></b></li>
<li><b><a href="https://dineshonjava.com/spring-mvc-with-hibernate-crud-example/"><span style="color: red;">Spring MVC with Hibernate CRUD Example</span></a></b></li>
<li><b><a href="https://dineshonjava.com/spring-3-mvc-tiles-plugin-with-example/"><span style="color: red;">Spring MVC Tiles Plugin with Example</span></a></b></li>
<li><b><a href="https://dineshonjava.com/spring-3-mvc-and-interceptor-with/"><span style="color: red;">Spring MVC Interceptor with example</span></a></b></li>
<li><b><a href="https://dineshonjava.com/integration-spring-mvc3-and-mongodb/"><span style="color: red;">Spring MVC with MongoDB CRUD Example</span></a></b></li>
<li><b><a href="https://dineshonjava.com/spring-3-mvc-internationalization/"><span style="color: red;">Spring MVC Internationalization &; Localization with Example</span></a></b></li>
</ul>
<p> ;</p>
</div>
<div class="wp-post-navigation"> 
									 <div class="wp-post-navigation-pre"> 
									 <a href="https://dineshonjava.com/spring-3-mvc-and-interceptor-with/">Previous</a> 
									 </div> 
									 <div class="wp-post-navigation-next"> 
									 <a href="https://dineshonjava.com/whats-new-in-spring-batch-2xx/">Next</a> 
									 </div> 
									</div>
<script type="text/javascript">
jQuery(document).ready(function($) {
 $.post('https://dineshonjava.com/wp-admin/admin-ajax.php', {action: 'mts_view_count', id: '613'});
});
</script>
Strategy Design Patterns We can easily create a strategy design pattern using lambda. To implement…
Decorator Pattern A decorator pattern allows a user to add new functionality to an existing…
Delegating pattern In software engineering, the delegation pattern is an object-oriented design pattern that allows…
Technology has emerged a lot in the last decade, and now we have artificial intelligence;…
Managing a database is becoming increasingly complex now due to the vast amount of data…
Overview In this article, we will explore Spring Scheduler how we could use it by…