SIGN UP MEMBER LOGIN:    
ARTICLE

Internationalization in JAVA

Posted by Abhishek Dubey Articles | Java February 08, 2012
Internationalization is the process of designing an application so that it can be adapted to various language and regions without engineering changes.
Reader Level:

Introduction

Internationalization is the process of designing an application so that it can be adapted to various languages and regions without engineering changes. Sometimes the term Internationalization is abbreviated as i18n, because there are 18 letters between the first "i" and the last "n"
Localization- Localization is the process of adapting software for a specific region or language by adding local specific components and translating text; its short name is l10n.

Characteristics of Internationalization:

  • A textual element such as a status message and the GUI  component lavels are not hard coded in the program. Instead, they are stored outside of the source code and retrieved dynamically.
  • Internationalization supports new language without recompilation.
  • Other culturally dependent data, such as dates and currencies, appear in formats that conform to the end user's  region and language.

Following step follow to create Internationalized application.

For example you have a frame with the two buttons "yes" and "no" and we want to display them in the French language so the button for "yes" changes to "Oui" and "No" changes to "Non" with out recompiling the program.
 

Step-1 First you create a properties file that stores the information; for creating it we save a simple text file with a .properties extension. For example xyz.properties. Write all the keys and their values using a Text Editor and here you must give any key's name on the left side and and key values on the right side.

Step-2
And save both files named as Msg_en_US.properties and Msg_fr_FR.properties.

internation1.gif

 Step-3 Defining the Locale Object identifies a particular language and country. The following language defines country.

standard.gifcountry.gif

 

Step-3 code

import java.util.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
 

public
class Internationalization_Demo extends JFrame
{
 
String Cap_yes;
String Cap_no;
 

static
String language;
static
String country;
 
JButton Button_yes,Button_no;
 

static
public void main(String[] args)
 {
 
if (args.length != 2)
    {//Use Internationalization_Demo fr FR (French)
          //or
     //Internationalization_Demo en US (US English)
     System.out.println("Use :java Internationalization_Demo Language(Ex-fr,en) country(FR,US)");
     System.exit(1);
    }
 
 language = new String(args[0]);
 country  = new String(args[1]);
 
 Internationalization_Demo frame=new Internationalization_Demo();

 // Event handle for click on close button
with the help of anonymous class 
 frame.addWindowListener(new WindowAdapter() {
                           public void windowClosing(WindowEvent e) {
                               System.exit(0);
                           }
                       });
 frame.setBounds(0,0,400,200);
 frame.setVisible(true);
  }//main close
 

public
Internationalization_Demo()
  {
 Locale locale = new Locale(language, country);
 ResourceBundle  captions= ResourceBundle.getBundle("Msg",locale);
 Cap_yes =captions.getString("yesMsg");
 Cap_no  = captions.getString("noMsg");
 Button_yes = new JButton(Cap_yes);
 Button_no =  new JButton(Cap_no);
 getContentPane().add(Button_yes,BorderLayout.WEST);
 getContentPane().add(Button_no,BorderLayout.EAST);
 }//Internationalization_Demo construct close
 }
//Internationalization_Demo class close

OUTPUT:

In this cmd we give the cmd argument as en US here en means  English language code and US for United state.

cmdInternationalizatio.gif

inter.. output.gif

In this cmd we give the cmd argument as fr FR here en means  french language and FR for French country code.

cmdInternationalizatio2.gif

inter.. output2.gif


Resources

Code Internationalization

Use of ByteStreams and CharacterStreams in JAVA

Learning JDBC (Java Database Connectivity)

Working with Hibernate - Display , Insert, Update and Delete in JAVA

Login to add your contents and source code to this article
share this article :
post comment
 
Become a Sponsor
PREMIUM SPONSORS
  • Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
    Get 2 Months Free of ASP.NET Hosting for Only $4.95/month! Receive FREE MS SQL and MySQL Databases Including ASP.NET 4/3.5, MVC 3.0, Silverlight 4, Windows 2008/IIS 7.0 Plus FREE IIS 7 Modules. Host UNLIMITED ASP.NET Web Sites - Click Here!
Team Foundation Server Hosting
Become a Sponsor