Magazine
 
Java Developer’s Desk
Internationalization
Internationalization is one of the key features of Java language, which makes a java application internationalized. In other words, nternationalization is the process of designing an application, which is able to adapt itself in different countries and regions without recompiling. Normally, software follows the conventions of region or country in which it is developed. This software is supposed to be used by the group of users familiar with this particular convention. For example, an American developer tends to develop software, which displays text in English, take the amount of money in “dollars” etc. On the other hand, a French developer is expected to develop software, which displays text in French, take currency in “franc”. Such software can’t be considered as internationalized. Java provides a solution of this issue. A truly internationalized program contains no hard coded area for a specific locale. For example, text, currency, date, number formats, audio clips etc., which makes an application locale specific, Instead of hard coding, these elements are stored outside of the program. Now, the program is not required to be compiled again when a new country or region requires support. When  

discussing internationalization, word “localization” comes to the front, which is the process of adapting software for a specific region or language by adding locale-specific components and translating text. It involves changing the language interaction, display of numbers, dates, currency, and so on. For better visualization, just go through the example below. Suppose, we have a program “InternationalizationDemo” in which the text to display is hard coded so it always displays the same text in English Language, no matter a Spanish person wants these texts in its own mother language. Internationalization
Demo.java: (Without Internationalization
Support)

import java.util.*;
public class
InternationalizationDemo {
public static void main(String[]
args) {
System.out.println(“The text
displayed is specific to
locale”+”
(“+Locale.getDefault().
getDisplayLanguage()+”,
“+Locale.getDefault().
getDisplayCountry ()+”).\n”);
System.out.println(“Hello, how
are you?”);
System.out.println(“Thanks to
visit.”);
}
}

 

Now you want this rogram to get internationalized so that itmay response according to the specific region and country i.e. locale (Remember no code changes are required for different locale). Just follow these steps:

1. Create Properties
Files:

Create “. properties” file containing a set of key and value pair. Remember to keep the keys same in all the files and provide values according to the locale in different files.

Properties Files Naming Convention:

Creating a default properties file is a good practice, which is available to the program by default. You can give any name to this file but remember to use the same name that your ResourceBundle uses (MessageBundle. properties file in our example). While naming other properties files follow the syntax:

PropertiesFileNameUsedIn ResourceBundle_language Code_countryCode.properties


Let’s create these files.
Default file:


Write down the following lines in a plain-text file (Default version) and save it as

Sept 2007 | Java Jazz Up | 10
 
previous
index
next
 
Pages: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29,

30
, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53 , 54, 55, 56, 57,

58
, 59, 60, 61, 62, 63 , 64, 65 , 66 , 67 , 68 , 69 , 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,   Download PDF