Internationalization in Struts2

The Struts2 provides feature t for web application can created for global use. The web content will be changed according to the language selection by the user at run time. To implement the above concept, Struts2 Internationalization and localization is used. Internationalization is known i18n and localization is known l10n.The main purpose of localization is to translate web content region specific information in the application into corresponding language and country code which is unique.

ISO Language code and Country Codes

Each language and country has unique language code and country code which is assigned by ISO (International Organization for Standardization). ISO is the network of the national standard institutes of various countries that define common standards for all the member countries.

Below is the list of some country code and their language code -
Country Name Country Code Language Language Code
United States US Englishen

A locale is an identifier and represents the local details of the user to the application. The local can be created by java.util.Locale class. When a user session begins, the Locale object is sent in the HTTP request as parameter.

Lets demostrate Internationalization in Struts2.
I created home page and there are three links for different languages like - English, German and French. By default all the content will display in English and content will be change according to the language selection by the user.

Follow the following steps to create this project :

Step 1: Create a Dynamic Web Project in eclipse - "Struts2I18N".
Step 2: Edit deployment descriptor web.xml :

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="" xmlns="" xmlns:web="" xsi:schemaLocation="" id="WebApp_ID" version="2.5">

Step 3: Copy required Struts2 jar files in WEB-INFlib folder in your project :

Step 4: Create a View page index.jsp :
<%taglib uri="/struts-tags" prefix="s" %>
    <title><s:text name="app.title"/></title>
  <table align="center" width=100%>
  <h2 align="center"><s:text name="app.head"/></h2>
  <td align="right">
   <s:text name="app.language"/> :
   <a href="home.action?request_locale=de">German</a> |
   <a href="home.action?request_locale=en">English</a> |  
     <a href="home.action?request_locale=fr">French</a> 
<td colspan="2"><hr></td>
<td colspan="2">
  <b><s:text name="app.message"/></b>
    <td colspan="2" align="center">
  <s:text name="app.footer"/>

Step 5: Create action class :
package techmyguru.actions;
import com.opensymphony.xwork2.ActionSupport;
public class HomeAction extends ActionSupport 
      public String execute() throws Exception 
  return SUCCESS;

Step 6: Create resource bundeled files

app.title=Struts 2 I18N demo
app.head=Struts 2 Internationalization demo
app.language=Select Language
app.message=In a Struts 2 web application you may associate a message resource property file with each Struts 2 Action class by creating a properties file with the same name as the Action class and having the .properties extension. This properties file must go in the same package as the Action class. For our tutorial example, let's say we want to place the form field labels into a separate file where we can easily change them and also provide the capability to display the labels in other languages.
app.footer=Copyright message of this content
app.title=Struts 2 I18N demoö
app.head=Struts 2 Internationalisierung Demo
app.language=Sprache auswählen
app.message=In einer Struts 2 Web-Anwendung können Sie eine Nachricht Ressourceneigenschaft Datei mit jedem Struts 2 Action-Klasse durch Erstellen einer Properties-Datei mit dem gleichen Namen wie die Action-Klasse und mit der. Erweiterung Eigenschaften zuzuordnen. Diese Eigenschaften Datei muss sich im selben Paket wie die Action-Klasse zu gehen. Für unser Tutorial Beispiel, sagen wir, wir wollen die Form Feld Etiketten in einer separaten Datei zu platzieren, wo wir leicht ändern und sie bieten auch die Möglichkeit, die Etiketten in anderen Sprachen anzuzeigen.
app.footer=Urheberrecht Botschaft dieser Inhalte
app.title=Montants 2 démonstration I18N
app.head=Montants 2 démonstration d'Internationalisation
app.language=Choisissez la Langue
app.message=Dans des Montants 2 application de web vous pouvez associer un dossier de propriété de ressource de message à chacun les Montants 2 classe d'Action en créant un dossier de propriétés avec le même nom que la classe d'Action et en ayant l'extension .properties. Ce dossier de propriétés doit entrer dans le même paquet que la classe d'Action. Pour notre exemple de classe de travaux dirigés, disons que nous voulons placer les étiquettes de champ de forme dans un dossier séparé où nous pouvons facilement les changer et fournir aussi la capacité d'afficher les étiquettes dans d'autres langues.
app.footer=Message de copyright de ce contenu

Step 7: Create

Step 8: Configure Action in struts.xml file :
<?xml version="1.0" encoding="UTF-8" ?>
"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
<constant name="devMode" value="true" />
<package name="default" extends="struts-default">
<action name="home" class="techmyguru.actions.HomeAction">
  <result name="success">index.jsp</result>

Step 9: Verify the project directory structure.
Struts2 Internationalization example

Step 10: Run the project and get output.
Struts2 Internationalization example

Select language German and get below output -
Struts2 Internationalization example

Select language French and get below output -
Struts2 Internationalization example

Previous Download Source Code Next

Share your valuable comment

Name :
Email Id : [ We will not publish your email id ]
Your Comment : [ Maximum 200 chars ]
Enter Security code :