Friday, June 19, 2009

Java Internationalization (II8N)

Internationalization (I18N) in Java

Java Internationalization (I18N) is the process of designing an application so that it can be adapted to different languages and regions, without requiring engineering changes. This model is to support many languages but only two of them, English (ASCII) and another one, at the same time. One have to specify the 'another' language,usually by LANG environmental variable. The above I18N-L10N model can be regarded as a part of this I18N model. gettextization is categorized into I18N model.

I18N is needed in the following places.

  • Displaying characters for the end users' native languages.
  • Inputing characters for the end users' native languages.
  • Handling files written in popular encodings [1] that are used for the end users' native languages.
  • Using characters from the end users' native languages for file names and other items.
  • Printing out characters from the end users' native languages.
  • Displaying messages by the program in the end users' native languages.
  • Formatting input and output of numbers, dates, money, etc., in a way that obeys customs of the end users' native cultures.
  • Classifying and sorting characters, in a way that obey customs of the end users' native cultures.
  • Using typesetting and hyphenation rules appropriate for the end users' native languages.

Java Internationalization (I18N) can be done with some handy modifications in our existing application. We have to know the two Internationalization (I18N) components that are packaged with the Struts Framework. The first of these components, which is managed by the application Controller, is a Message class that references a resource bundle containing Locale-dependent strings.

The second Internationalization (I18N) component is a JSP custom tag, <bean:message /> , Which is used in the View layer to present the actual strings managed by the Controller.


Java Internationalization (I18N) is a set of simple Java properties files. Each file contains a key/value pair for each message that you expect your application to present, in the language appropriate for the requesting client.

Locale objects are only identifiers. After defining a Locale, you pass it to other objects that perform useful tasks, such as formatting dates and numbers. These objects are called locale-sensitive, because their behavior varies according to Locale. A ResourceBundle is an example of a locale-sensitive object.

Internationalization Sample Program

import java.util.*

public class I18NCode
{
public static void main(String args{})
{

String language;
String country;

if (args.length != 2)
{

language = new String("en");
country = new String("US");

}else{

language = new String(args[0]);
country = new String(ars[1]);
}

Locale currentLocale;
ResourseBundle messages;

currentLocale = new Locale(language, country);
messages = ResourseBundle.getBundle("MessagesBundle", currentLocale);

System.out.println(messages.getString("Hai");
System.out.println(messages.getString("How are");
System.out.println(messages.getString("You");

}
run this program in the following way:

java I18NCode en US
(or)

java I18NCode fr FR

0 comments:

Blog Widget by LinkWithin

JS-Kit Comments

  © Blogger template Newspaper III by Ourblogtemplates.com 2008

Back to TOP