A primary design goal of Java is to allow developers to write software that can be
deployed easily in a variety of world markets. But these markets all use different
languages, for your product to be accepted in these markets, it must able to conform to
language of different locations.
Fortunately, in the Java Development Kit (JDK) version 1.2 and above, have Locale and
its supporting classes to help write code that can adapt to different languages without ant
modifications.
How do you do it?
Conclusion
Internationalization helps to maintain a single source code base for all language versions
of your product. The main benefit of designing an application for the global marketplace
is more customers. Many countries require that companies purchase applications that
support their language and culture. Global planning ensures that your application is easier
to translate and maintain. A well-designed application functions the same way in all
locales
deployed easily in a variety of world markets. But these markets all use different
languages, for your product to be accepted in these markets, it must able to conform to
language of different locations.
Fortunately, in the Java Development Kit (JDK) version 1.2 and above, have Locale and
its supporting classes to help write code that can adapt to different languages without ant
modifications.
The term internationalization (a.k.a. globalization) can be defined as building or
modifying an application to prepare it for use in other countries or cultures. You also may
have come across the term I18N, which refers to the number of letters (18) between the I
and the N in the word internationalization. Similarly, localization (which you may see
referred to as L10N) refers to the process of making an application suitable for a
particular geographic location, country, or culture.
It helps to think of the terms in this manner: If internationalization is the process of
making an application generic, localization is the process of making it specific.
According to Sun, "All locale-sensitive classes must be able to access resources
customized for the locales they support. To aid in the process of localization, it helps to
have these resources grouped together by locale and separated from the locale-neutral
parts of the program."
In Java, the process of localizing is made simpler with the use of the locale class. A
locale is an identifier for a combined language and geographic area. Locales serve as
requests for certain deliverables from another object. A UK locale passed to a
Measurement object requests that the measurement is delivered in metrics; the US locale
would return U.S. customary symbols.
The Java Development Kit 1.1 predefines a number of locale objects like:
locale.CANADA
locale.CANADA_FRENCH
Included in the Java 1.1 API are the java.text package and the ResourceBundle classes
contained in the java.util package, which together with the Locale classes make up the
backbone of localization on the Java platform. Resource bundles use a cascading
mechanism to provide the best translation support with the minimal amount of work for
both the developer and resources of the computer. In this scheme, the developer creates
files that define a lookup table for translation and adds an encoding to the names of these
files to specify the locale of the file.
How do you do it?
There are many factors to consider when building a culturally and geographically neutral
application. For example, how do you effectively display numbers, currencies, dates,
times, text, and sort orders of Strings, along with the entire user interface? One of the
most important aspects of creating a global application is to avoid hard-coding any
locale-specific data or text.
The process of internationalizing/localizing an application includes these steps:
- Identifying and separating culture- and geographic-specific code, content, and design
- Developing a set of classes describing specific information (such as fields) for each locale (Extend the class Resource Bundle when feasible to simplify the translation process.)
- Developing your Resource Bundle files as you build the application
- Loading the bundles into an object array
- Generating a single translation file using the object array
- Translating the file into the proper language (see note below)
- Conducting QA on translation effort
- Saving the file in the resource directory for the locale
- A note on translation Often, text translation is the most time-intensive and costly part of localizing a
project. It requires significant effort to simply translate all text and text strings. Not
only must you find a reliable translator who is proficient in a language, he or she
should have a technical background and be familiar with technical style guides for
the locale that are equivalent to the quality your own. Furthermore, the translator
must have a good background in locale-specific user interface
Resource Bundle Files
If the developer chose to use property files to represent the lookup tables for United
States English, they might look like this:
# File Name: BOKBundle_en_US.properties
# [Language code for English (en) and Country code for USA (US)]
#
# Welcome message in US English
#
WelcomeMessage = Hello
Or for Chinese Character the file might look like this:
# File Name: BOKBundle_zh_CN.properties
# [Language code for Chinese (zh) and Country code for China(CN)]
#
# Welcome message in Chinese
#
WelcomeMessage = \u4F60\u597D\u3002
The nomenclature is:
<Bundle name>_<language>_<region/country>. Property
Where the <language> and <region/country> are the corresponding language and
Country
The Welcome message in this case is written in Unicode; lucky for us Java uses Unicode
to represent the characters. (Unicode defines a fully international character set that can
represent all of the characters found in human languages.)
Finding the Locale
Locale Identification by Java can be done using the java.lang.System Class. Among the
facilities provided by the System class is access to externally defined "properties".
To find out the Language and Region of a System we can use System Class.
// Getting the Operating system language, default is English String language = System.getProperty ("user.language","en"); // Getting the Operating system region, default is US String region = System.getProperty ("user.region","US");
Thus we can find the locale to use as:
Locale currentLocale = new Locale (language, region);
Locating the Bundle and Reading the Message
To locate the corresponding the Resource Bundle for a Locale and to get the value of a
key
ResourceBundle bokBundle = ResourceBundle.getBundle ("BOKBundle", currentLocale); String msg = (String) bokBundle.getObject ("WelcomeMessage");
If the Value of key (WelcomeMessage) is not available in the corresponding Locale
Bundle (say BOKBundle_zh_CN.properties), the value is searched in the default Bundle
(BOKBundle.properties) before throwing the Error.
Formatting Date and Time
The date, time, and number formatters are necessary because most countries have
different conventions for displaying this data. For example, an American English speaker
would write the date "Monday, March 24, 2003" And a French speaker would write
"lundi 24 mars 2003".
Java has provided java.text.DateFormat Class for this very same purpose.
The Following snippet will Display the date and time in Locale specific Format.
Date dt = new Date (); DateFormat time = DateFormat.getTimeInstance (DateFormat.FULL, currentLocale); DateFormat date = DateFormat.getDateInstance (DateFormat.FULL, currentLocale); System.out.println (" The Date is: " + time.format (dt)); System.out.println (" The Time is: " + date.format (dt));
Formatting Text/Using Placeholders
The major chunk of Externalization is in externalization and Internationalization of Text;
it is not as simple as at seems as simply moving the text to a property file will not solve
the purpose.
Different languages have different Grammars.
E.g. Of the English text “I am Sanchika” simply extracting the text “I am” and pushing
in .property file will not work, as when localizes for Japan the text will become “ Koreva
des Sanchika” which does to translate to “I am Sanchika”.
Observe the Following Code, the grammar of US and France is considered in the
property files and The Placeholders (Nouns) are replaced by the Data types definitions.
From code MessageFormmatter is used to construct the Text using object Array and the
grammar from the property files.
# From French Property File message2 = \u00c0 {0,time,short} sur {1,date,long}, nous avons d\u00e9tect\u00e9 le working de {2,number,integer} utilisateurs sur {3} d'cImper.. # From US Property File message2 = At {0,time,short} on {1,date,long} , we detected {2,number,integer} users working on {3}. Code: MessageFormat formatter = new MessageFormat(""); formatter.setLocale(currentLocale); Object[] message2Arguments0 = { new Date(), new Date(), new Integer(746), “MAC OS X”, }; formatter.applyPattern(bokBundle.getString("message2")); output = formatter.format(message2Arguments0);
Converting to Unicode Text
SUN and other vendors of JDK provide a utility/tool for converting Native language to
UTF-8 Character code file, which can be opened in simple text editor.
The Code jar contains ‘kanji.properties ‘ which has native Japanese Encoding; this can be
converted to is a UTF-8 file by running following Java tool from the prompt.
native2ascii kanji.properties kanji_Unicode.properties
This will create a new file ‘kanji_Unicode.properties’ which will have all native codes
converted to there equivalent UTF-8 Characters.
Using the Code
Expend the jar in your working folder and from the command prompt run the stand-alone
swing application demonstrating the use of same code base for two different locales ( US
and JPN ).
Conclusion
Internationalization helps to maintain a single source code base for all language versions
of your product. The main benefit of designing an application for the global marketplace
is more customers. Many countries require that companies purchase applications that
support their language and culture. Global planning ensures that your application is easier
to translate and maintain. A well-designed application functions the same way in all
locales