Tuesday, July 8, 2008

Localization & Internationalization

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

An internationalized program has the following characteristics:

1. With the addition of localized data, the same executable can run worldwide.
2. Textual elements, such as status messages and the GUI component labels, are not hardcoded in the program. Instead they are stored outside the source code and retrieved dynamically.
3. Support for new languages does not require recompilation.
4. Culturally-dependent data, such as dates and currencies, appear in formats that conform to the end user's region and language.
It can be localized quickly.

Sample Code :

1. First get the Locale data's like country language.

String language="en";
String country="US";
currentLocale = new Locale(language, country);

2. Before that we should create the message bundle (It's nothing but properties file which is include the content of page)

MessagesBundle.Properties
MessagesBundle_de_DE.properties
MessagesBundle_en_US.properties

3. Once it's created ,you can access the message bundle based on locale using the ResourceBundle.

ResourceBundle messages =ResourceBundle.getBundle
("MessagesBundle",currentLocale);


System.out.println(messages.getString("greetings"));

No comments: