Online Training Spring Hibernate Training in Delhi R Programming Training Course Big Data and Hadoop Training Java Training

STRUTS INTERNATIONALIZATION

In this tutorial we shall see how to implement Internationalization (abbreviated as I18N) in Struts.

Ads

Tutorials   
Struts 2.5.10.1 General Availability - released Login form in Struts2 version 2.3.16 Struts 2 Login Application Struts 2 version 2.3.16.3 released Struts 2 version 2.3.15.3 released Struts 2 Hello World Annotation Example Struts Roseindia Struts 2 Tutorial: Easy steps to learn Struts 2 Difference between Struts and Spring Apache Struts 2.3.15.2 launched to fix vulnerable Feature Struts2 Application in Eclipse: Running the application in Eclipse IDE Struts 2 Hello World Application using Eclipse Interceptors in Struts 2 Struts 2 Action Tag Struts 2 in Agile Development Environment Struts 2 UI Tags Generic Tags Creating own Interceptor What are Interceptors in Struts 2 and how do they work? Results Value Stack / OGNL Action in Struts 2 Framework Struts 2 Interceptors Struts 2.3.15.1 Maven - How to use Maven dependency of Struts 2.3.15.1? Download Struts 2.3.15.1 How Struts 2 Framework works? Architecture of Struts 2 Framework Features and Enhancements in Struts 2.3.15.1 Struts 2 Tutorials - Struts version 2.3.15.1 Struts 1 Tutorial and example programs Struts Tutorial What is Struts Struts Flow Diagram Step By Step Struts Tutorial Struts 2 Login Form Example Struts Video Tutorials Struts 2 Hello World Example Introduction to Struts 2 Framework Downloading and Installing Struts 2.3.8 In Struts What is Model? What is Struts? Download Struts What is Struts Framework? Struts Framework Latest Version of Struts Framework Downloading Struts Official example Struts 2.3.8 released with new features Struts 2.3.8 Tutorials and Examples Hibernate4 Struts Integration Struts2 Tiles Example
Ads

STRUTS INTERNATIONALIZATION
--------------------------------
by Farihah Noushene B.E.
================================
(published in Developer IQ - Oct 2005)

     

In this tutorial we shall see how to implement Internationalization (abbreviated as I18N) in Struts.

The Multinational Corporations have their branches in various parts of the world. so, they must provide products and services to their clients and customers in their traditional way. The customers will expect the product to work in their native languages especially the date, time, currency etc.,. So, the we should not make any assumptions about their clients region or language. If such assumptions become invalid, we have to re-engineer the applications.

Internationalization or I18N is the process of designing the software to support multiple languages and regions, so that we don't need to re-engineer the applications every language or country needs to be supported.

Struts provides various locale sensitive JSP tags which can be used to make the applications simpler. With this short introduction we shall see how to implement i18n in a Simple JSP file of Struts.

g:\>md localedemo
g:\>cd localedemo
g:\localedemo>edit localedemo.jsp

// g:\localedemo\localedemo.jsp

<%@ page language="java" %>

<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>

<html:html locale="true">
<body bgcolor=pink>

<bean:message key="index.info" />

</body>
</html:html>
--------------------------------------

Next copy struts-blank.war to f:\tomcat41\webapps and start the tomcat with JAVA_HOME as jdk1.4. A folder named struts-blank will be created. Rename the folder as localedemo. Copy the above JSP file to f:\tomcat41\webapps\localedemo.

Now we have to edit the property files for various locales. The struts framework(struts1.1) provides a property file named application.properties. It is present in the folder f:\tomcat41\webapps\localedemo\web-inf\classes\resources. We have to add our own property file in this folder only. Our property file much be named along with the language code

For example the language code of
  
1. German - de
   2. Spanish - es
   3. English - en
   4. Korean - ko
   5. French - fr
   6. Italy - it

So, when we write i18n message in German language it must be placed in property file named application_de.properties and all the properties files must be present in the resources folder only. Also when we write the property file of a particular language it need not be of the same language. For example we can create application_de.properties and write the message in french or english. In fact, the message does not depend on any language. It is a simple key value pair. The message we give for the key is just substituted. The property file to locate the value of key depends on the language settings of the browser. For this example, we will write four properties file as follows.

f:\tomcat41\webapps\localedemo\web-inf\classes\resources\ application_de.properties

index.info=GERMANY
---------------------------------------------------------
f:\tomcat41\webapps\localedemo\web-inf\classes\resources\ application_es.properties

index.info=SPAIN
-----------------------------------------------------------
f:\tomcat41\webapps\localedemo\web-inf\classes\resources\ application_en.properties

index.info=ENGLISH
-----------------------------------------------------------
f:\tomcat41\webapps\localedemo\web-inf\classes\resources\ application_fr.properties

index.info=FRANCE
------------------------------------------------------------
Also append this text in the application.properties file
  index.info=STRUTS TUTORIAL.

Now we have to add entry in the
struts-config.xml file for all the properties files. The entry and its corresponding portion is shown below.

<!-- Message Resources Definitions -->

  <message-resources parameter="resources.application_fr"/>
  <message-resources parameter="resources.application_es"/>
  <message-resources parameter="resources.application_en"/>
  <message-resources parameter="resources.application_de"/>
  <message-resources parameter="resources.application"/>

Now restart the Tomcat server. Open the Internet Explorer and type the URL as http://localhost:8080/localedemo/localedemo.jsp. We will get the message 'ENGLAND'. This is because our default browser language is 'United States English'.

Now we have to change the language settings of the browser to change the locale. For that, Open a new Internet Explorer, goto 'Tools' menu and select the 'Internet Options'. In the 'Internet Option' dialog box, select 'General' tab and click the 'Languages...' button. We will get 'Language Preference' dialog box. There click 'Add...' button and add the languages. For this example add English, Spanish, German and French. Here we have languages specific to particular region. For example we have, French Belgium, French Canada, French France etc., we can select any one of these in all cases. Next select 'German' and by using the 'Move up' button, place it on the top. Now type the URL as http://localhost:8080/localedemo/localedemo.jsp. We will get the message 'GERMAN' Similarly place 'Spanish' and 'French' at the top, we will get the message 'SPAIN' and 'FRANCE' respectively.
---------------------------------------------------------------------------
 

     


 

Advertisements

Ads

Online Training Classes

Share on Google+Share on Google+

STRUTS INTERNATIONALIZATION

Posted on: January 19, 2008 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Advertisements

Ads
 

Discuss: STRUTS INTERNATIONALIZATION   View All Comments

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:5
sridhar
May 16, 2012
i18n doubt

hi i have doubt i have created i18n application by using hyperlinks but i need to create using dropdowns .i tried with select and javascript onselect() .please suggest me how to create it
nagaraju Dameruppula
September 12, 2013
Struts 1 with korean resource property file

Hi All, I have a problem in migrating the struts1 to korean language can somebody help with an example. I will be very much please and eagerly waiting for the response. Thanks and Regrags Nagaraju.Dameruppula
nag
September 12, 2013
d

can you show example with korean resource property file please.
nagaraju.da
September 13, 2013
4. Korean - ko

Hi, Can you please show how to configure korean property for Korean language. Regards Nagaraju
nagaraju.da
September 13, 2013
Korean properties file in struts

Hi, Can you please help how to configure korean property file for defining korean language or implementing struts for korean language Regards Nagaraju.D

Ads

 

Ads