Internalisation and Localisation
Internalisation and Localisation
N AND
LOCALISATION
3
INTRODUCTION
• Internationalization is the process of
designing an application so that it can be
adapted to various languages and regions
without engineering changes.
• unicode
• locale class
• resourse bundles
Locale cLass
Locale
• The classes for formatting date, time, and numbers, and for sorting
strings are grouped in the java.text package.
• Every Swing class has a locale property inherited from the Component
class.
Creating Locale Object
• Constructor:
Locale (String Language)
Locale (String Language, String Country)
Locale (String Language, String Country, String Variant)
Language and Country Codes
Country Country Code Language Code
Spain ES es
Denmark DK da
Germany DE de
Greece GR el
China CN zh
Sweden SE sv
France FR fr
Norway NO no
Methods of Locale Class
Constructor:
There is only default Constructor for TimeZone.
Methods of TimeZone Class
• String getID()
This method gets the ID of this time zone.
DateFormat Class
• An abstract class for date/time formatting subclasses which formats and
parses dates or time in a language-independent manner.
• Constructor:
protected DateFormat()
• Constants:
• SHORT is completely numeric, such as 01.12.52 or 3:30pm
• MEDIUM is longer, such as Jan 12, 1952
• LONG is even longer, such as January 12, 1952 or 3:30:32pm
• FULL is pretty completely specified, such as Tuesday, April 12, 1952 AD
or 3:30:42pm IST.
Methods of DateFormat Class
• Constructors:
DateFormatSymbols()
DateFormatSymbols(Locale locale)
• Methods:
String[] getAmPmStrings() String[] getEras()
String[] getMonths()
Formatting numbers
Formatting Numbers
• Numbers are formatted using an abstract base class
java.text.NumberFormat .
Number: 5000.555
United States: 5,000.555
France: 5000,555
Germany: 5.000,555
Methods
• getInstance(): NumberFormat
• getInstance(locale: Locale): NumberFormat
• getIntegerInstance(): NumberFormat
• getIntegerInstance(locale: Locale): NumberFormat
• getCurrencyInstance(): NumberFormat
• getNumberInstance(): NumberFormat
• getNumberInstance(locale: Locale): NumberFormat
• getPercentInstance(): NumberFormat
• getPercentInstance(locale: Locale): NumberFormat
Formatting Numbers
• Currency Format:
NumberFormat nf = NumberFormat.getCurrencyInstance(Locale l);
• Percent Format:
NumberFormat nf = NumberFormat.getPercentInstance(Locale l);
DecimalFormat Class
• A pattern can specify the minimum number of digits before the decimal
point and the maximum number of digits after the decimal point.
• The characters '0‘ and '#' are used to specify a required digit and an
optional digit, respectively.
• If there are more actual digits before the decimal point, all of them are displayed.
• If there are more than three digits after the decimal point, the number of digits is
rounded.
Example:
1987.16920 will be formatted as: 1987.169
1389.2387 will be formatted as: 1389.239
Resource Bundles
Resource Bundles
• A resource bundle is a Java class file or text file that provides locale-specific
information.
• When a locale-specific resource is needed, our program can load it from the
resource bundle appropriate for the desired locale.
Resource Bundles
• The resources are placed inside the classes that extend the
ResourceBundle class or a subclass of ResourceBundle.