Internationalization
Internationalization is the process of preparing an application to support various languages.
Localization
is the ability to customize a program to the user's language (e.g., for prompts and error messages) and display characteristics (e.g., for how to display times and dates). The different customizations are defined by individual areas or regions, each called a Locale.Before you can localize any programs, you need to isolate the locale dependent pieces. This isolation process is called internationalization. In the simplest case, this involves the moving of all String constants into something called a ResourceBundle. However, resource bundles are not restricted to just text messages and may include images, sounds, and numeric information. And this isn't the only step involved.
Three areas that are important in Internationalization are:
1. Data Input
2. Data Storage
3. Data Presentation (Formatting)
Locale
A Locale is a language or subset of language that includes both regional and language-specific information.
A locale defines a specific local area, without specifying any other details about that area's needs. The class Locale resides in the java.util package.
A Locale is specified by adding a trailing string to an identifier that specifies a ResourceBundle. The first three letters are an underscore ('_') and a two character language code (lowercase). The next three are an underscore and a two character country code (uppercase). For ex. _fr_FR (or) _fr_CA.
Locale construction :
Locale l = new Locale(String lang, String country, String variant);
Remember variant is optional.
Every runtime has a default locale.
Locale l = Locale.getDefault();
To retrieve a list of all the available locales, use
Locale list[] = DateFormat.getAvailableLocales();.
To retrieve the individual locale "components" as strings, use
locale.getLanguage(), locale.getCountry(), and locale.getVariant().
Resource Bundles
The means to do this is through the ResourceBundle class. Resource bundles provide a simple key-value lookup and may be provided via .class or .properties files.
Using Class File
1. subclass ListResourceBundle
2. override the getContents method to return an Object[][].For each pair of elements in the array, the first would be the lookup key and the second the value for the key for the given Locale.
3. You would then use this bundle to lookup resources in a two step process: load the resource list and search it. To load the list, use ResourceBundle.getBundle(). This will load the bundle for the appropriate Locale.
Java.text Package
Provides classes and interfaces for handling text, dates, numbers, and messages in a manner independent of natural languages.
1. BreakIterator
The BreakIterator
class implements methods for finding the
location of boundaries in text.
2. Collator
The Collator
class performs locale-sensitive String
comparison.
3. Format
Format
is an abstract base class for formatting locale-sensitive
information such as dates, messages, and numbers.
4. DateFormat
DateFormat is an abstract class for date/time formatting subclasses which formats and parses dates or time in a language-independent manner.
5. SimpleDateFormat
SimpleDateFormat
is a concrete class for formatting and parsing dates
in a locale-sensitive manner.
6. NumberFormat
NumberFormat
is the abstract base class for all number formats.
7. DecimalFormat
DecimalFormat
is a concrete subclass of NumberFormat
that
formats decimal numbers.
Unicode
Unicode standard contains 34,168 distinct coded characters derived from 24 supported language scripts. These characters cover the principal written languages of the world. Additional work is underway to add the few modern languages not yet included.
InputStreamReader
An InputStreamReader is a bridge from byte streams to character streams: It reads bytes and translates them into characters according to a specified character encoding. The encoding that it uses may be specified by name, or the platform's default encoding may be accepted.
Each invocation of one of an InputStreamReader's read() methods may cause one or more bytes to be read from the underlying byte-input stream. To enable the efficient conversion of bytes to characters, more bytes may be read ahead from the underlying stream than are necessary to satisfy the current read operation.
For top efficiency, consider wrapping an InputStreamReader within a BufferedReader. For example:
BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); OutputStreamWriter
An OutputStreamWriter is a bridge from character streams to byte streams: Characters written to it are translated into bytes according to a specified character encoding. The encoding that it uses may be specified by name, or the platform's default encoding may be accepted.
Each invocation of a write() method causes the encoding converter to be invoked on the given character(s). The resulting bytes are accumulated in a buffer before being written to the underlying output stream. The size of this buffer may be specified, but by default it is large enough for most purposes. Note that the characters passed to the write() methods are not buffered.
For top efficiency, consider wrapping an OutputStreamWriter within a BufferedWriter so as to avoid frequent converter invocations. For example:
Writer out = new BufferedWriter(new OutputStreamWriter(System.out));