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
- Textual elements such as a status message and the GUI component labels are not hardcoded in the program. Instead, they are stored outside of the source code and retrieved dynamically.
- Internationalization supports a 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 an 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 "None", without 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. Here, you must give any key's name on the left side and key values on the right side.
Step-2: And save both files named as Msg_en_US.properties and Msg_fr_FR.properties.
Step-3: Defining the Locale Object identifies a particular language and country. The following language defines country.
Step-4 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)
- {
-
-
- 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();
-
- frame.addWindowListener(new WindowAdapter() {
- public void windowClosing(WindowEvent e) {
- System.exit(0);
- }
- });
- frame.setBounds(0,0,400,200);
- frame.setVisible(true);
- }
-
- 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);
- }
- }
Output
In this cmd, we give the cmd argument as en-US here en means, English language code and the US for the United States.
Summary
In this article, we learned about Internationalization in Java and how to use Internationalization in Java Program.