Frameworks| Hibernate| Struts| JSF| JavaFX| Ajax| Spring| DOJO| JDO| iBatis| Questions?

 

 

 

 

 

 

 

 

 

 

 

 

 

Search Tutorials

Latest Questions
Comments
 
STRUTS INTERNATIONALIZATION 
 

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

 

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.
---------------------------------------------------------------------------
 

                         


 

» View all related tutorials
Related Tags: c exception time io scope multiple type request cookie default ip page value tag name attribute this oo row define

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 

Current Comments

25 comments so far (
post your own) View All Comments Latest 10 Comments:

I want to know how I can build a hindi / english supported application using i18n feature of struts2.
Please send me a prepared resource bundle "properties" file for hindi language.
Please send me steps also to use it in my application.

Manohar Singh Shekhawat

Posted by Manohar on Friday, 04.10.09 @ 18:35pm | #86714

There is no need to include all resource files in the struts-config. Include only the standard one. The rest will be detected automatically. ie, include only..

<message-resources parameter="com/myapp/struts/ApplicationResource"/>

Posted by Richy on Tuesday, 08.26.08 @ 09:16am | #75182

Hi I am doing internationalization for struts based project.my problem is i want to change ApplicationResource bundel name,i used LocaleAction and it workes fine but if i change the name of the ApplicatinoResource_ja.peroperties to Application126_ja.peroperties then in jsp it shows key not found problem.can anybody help me out?how to change name of the peroperties file.

Posted by Arunkumar on Thursday, 04.17.08 @ 15:04pm | #56792

want to know how to make hindi supported web site

Posted by kk on Wednesday, 03.26.08 @ 16:07pm | #54393

It is very good for a newbie. Thank you.

Posted by Indranil Bhakat on Monday, 02.25.08 @ 20:20pm | #49975

I am also facing the same issue.Please help

Posted by Akansha on Monday, 01.21.08 @ 13:14pm | #45753

How Can I Set the Default LOCALE Language (Ex. Application en Francais, Applicazione in Italiano) in a STRUTS 1.x Application ?

Is There some <TAG> in Struts-config or web.xml
or some use about <PLUGIN> ?

Please Help Me ,it' s very very urgent & important for my work ! Many Thanks.

Posted by Julian on Thursday, 01.17.08 @ 19:09pm | #45453

what is struts?

Posted by ganesh on Thursday, 12.27.07 @ 18:24pm | #43962

ok, i have the language change in an action. But my problem is, i have the main tile with the buttons for languages, and below i have other tiles where different pages are loaded. I want to be able to choose the language, (perform the action) and just reload the whole page with the new language. I mean, is it possible to perform an action without forwarding to a specific page? I would want just to change the language, and reload the current page (whatever is is) with the new language selected. Hope i as clear. Thanks in advance.

Posted by pantominas on Tuesday, 06.26.07 @ 15:25pm | #20211

with out changing browser settings how can we display different locales.one can came from french how can he access the page displayed in french.
with out changing browser options can u provide one sample example with jsp and servlet.

Posted by ranjith on Friday, 06.15.07 @ 14:05pm | #19303

Training Courses
Tell A Friend
Your Friend Name
Software Solutions
Least Viewed
Most Rated
Recently Viewed
Search Tutorials

 

 
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Indian Software Development Company | iPhone Development Company in India | Flex Development Company in India | Java Training Delhi | Java Training at Noida |

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2008. All rights reserved.