Thursday 27 June 2013


i18n  In JAVA

I 18 n-:

Internationalization is a process of creating internationalized application. An internationalized application can adopt itself according to preferences of user of a different country.
MC Dee Burger Example…..(in India Veg, in China Jingur Burger)
Usually following preferences are change out from one country to another.
Language, number format, date format etc.
First step of internationalization is the representation of the user preferences in the object form.
Java.util.Locale This class provided to represent user preferences as Object.
A local object can be created using following Constructor-:
public Locale(String langCode);
public Locale(String langCode,String countryCode);
public Locale(String langCode,String countryCode,String variant);
Note-: two letter code are used to represent countries and language
Country code used capital letter and language code used small letter.
Difference B/W Language and Script-: Both are different. (Varient)
Commonly used method of Locale class -:
getAvailableLocale()-: is used to find out the locale supported by JRE.
public static Locale();
getDefault()-: is used to find out the default locale of the JRE.
public static Locale getDefault
getLanguage()-: is used to find out then language code of a Locale;
public string getLanguage();
getDisplayLanguage()-: is used to find out language name of a locale .
public String getDispalyLanguage();
getCountry()-: is used to find out country code of a locale;
public String Country();
getDisplayCountry()-: is used for find out country name of a locale.
public String getDisplayCountry();
getDisplayName()-: is used to find out language name and country name of a locale.
public String getDisplayName();
In the basis of locale class java class can be divided in to two categories-:
*    Locale Sensitive
*    Locale Insensitive
Locale sensitive can changes its behavior according to the given locale java.text.NumberFormat & java.text.DateFormat are two locale sensitive class.
NumberFormat class is used to apply locale specific number & currency formatting.
These are including in sensitive things-:
Language, Number, Currency, Date, Time……..
Following step are required to apply locale specific or currency formatting--:
*    A NumberFormat object is created using either of the following method.
// to apply number formatting
public static NumberFormat getNumberInstance(Locale locale);
// to apply currency formatting
public static NumberFormat getCurrencyInstance(Locale locale);
*    Number or Currency formatting apply using the format() method of NumberFormat Class.

public String format(long no);
public String format(double no)
Let’s Try this using a Example---:
Apply Locale specific Date & Time Formatting….
Step-: 1. A DateFormat object is created using either of the following method…
// to apply Date formatting
public static DateFormat getDateInstance(int style, Locale locale);
// to apply Time formatting
public static DateFormat getTimeInstance(int style, Locale locale);

Note-: Date & Time can be display in following style--:
DateFormat class provide static final integer data member to specify style
Commonly use data member is --:
DateFormat.SHORT
DateFormat.LONG
DateFormat.FULL

Step.2 Date or Time formatting apply using the format() method of DateFormat Class.
public String format(Date d);
Note-: DateFormat class not convert date & Time from one time zone to another time zone, it simply apply formatting
 

Steps required changing Textual content of an Application ---:
Step 1--:For each locale which is to be supported by Application, properties files are created and textual contents specified to the locale are stored in file as properties
A properties file of each locale is name using the following convention...
<Fromname_languageCode.properties>
Example-: If contents of from name Adder are to be displayed in Hindi & English following properties are be created…
Adder_hi.properties
Adder_en.properties

Step--:2 The Application java.util.ResourceBundle classs is used to reading properties from the locale specified properties files.

A ResourceBundle object can be obtained as follows-:
public static RsourceBundle getBundle(String baseName, Locale locale)
ResourceBundle class provide a method to read the value of property.
public string getString(String propName);
Step required creating a properties file other than English language---:
Step-1 Use translator tools to convert English contents in to the target language.
Use Google Translator tools for this purpose. Suppose converts text are--:
Step-2 Save this file by selecting UTF-8 encoding.
Step: 3 Use native2ascii tools to convert UTF coding to ascii coding...
This file will be created with name Adder_hi.properties