Introduction to Internationalization
- Java Internationalization (I18N) is Java's built-in support for making your application able to serve users in multiple languages.
- It also covers formatting of numbers, adjustment to date and time etc.
- Internationalization is often abbreviated I18N. The 18 refers to the 18 characters between the first letter I, and the last letter N. Localization is similarly abbreviated as L10N.
Why an Internationalization Component?
- The reason you have an internationalization layer or component is to separate the internationalization code from the rest of the application.
- You may choose to use Java's built-in internationalization features. By encapsulating your internationalization code in an I18N component.
- You can change the API used inside it, without affecting the rest of your application.
Java Internationalization Classes
Locale |
The Locale class represents a language and a country or region. A Locale may also represent a certain type of formatting - e.g. date or number formatting. |
ResourceBundle |
The ResourceBundle class can contain localized texts or components (objects). You obtain a ResourceBundle for a specific Locale, and thus obtain texts or objects localized to that Locale. |
NumberFormat |
The NumberFormat class is used to format numbers according to a certain Locale. |
DecimalFormat |
The DecimalFormat class is used to format numbers according to customized formatting patterns. These patterns are also Locale sensitive. |
DateFormat |
The DateFormat class is used to format dates according to a specific Locale. |
SimpleDateFormat |
The SimpleDateFormat class is used to parse and format dates according to custom formatting patterns. These patterns are also Locale sensitive. |
Locale class
A Locale object represents a specific geographical, political or cultural region.
An operation that requires a Locale to perform its task is called locale-sensitive and uses the Locale to tailor information for the user.
For example, displaying a number is a locale-sensitive operation--the number should be formatted according to the customs/conventions of the user's native country, region, or culture.
Create a Locale object using the constructors in this class:
Locale(String language) Locale(String language, String country) Locale(String language, String country, String variant)The language argument is a valid ISO Language Code. These codes are the lower-case, two-letter codes as defined by ISO-639. You can find a full list of these codes at: www.loc.gov/standards/iso639-2/englangn.php
The country argument is a valid ISO Country Code. These codes are the upper-case, two-letter codes as defined by ISO-3166. You can find a full list of these codes at : www.iso.ch/iso/en/prods-services/iso3166ma/02iso-3166-code-lists/list-en1.php
Because a Locale object is just an identifier for a region, no validity check is performed when you construct a Locale. If you want to see whether particular resources are available for the Locale you construct, you must query those resources. For example, ask the NumberFormat for the locales it supports using its getAvailableLocales method.
Note: When you ask for a resource for a particular locale, you get back the best available match, not necessarily precisely what you asked for.The Locale class provides a number of convenient constants that you can use to create Locale objects for commonly used locales. For example, the following creates a Locale object for the United States:
Locale.US



