8.11.1 Internationalizing the Application

If you are involved in developing global software, then you will be aware of the fact that one of the great commandments of internationalization is to separate text, labels, messages and other locale-sensitive objects from the core source code. This helps to maintain a single source code base for all the language versions of your product. It also facilitates translations because the resources that can be localized are identified and isolated.

 

The Internet demands global software i.e., software that can be developed independent of the countries or languages of its users, and localized for multiple countries or regions. The Java Platform provides a rich set of APIs for developing global applications. The internationalization of APIs are based on the Unicode 2.1 character encoding and include the ability to adapt text, numbers, dates, currency, and user-defined objects to any country's conventions.

 

The Unicode Standard defines the universal character set. Its primary goal is to provide an unambiguous encoding of the content of plain text, ultimately covering all languages in the world. Currently  Unicode contains a large number of characters covering most of the currently used scripts in the world. It also contains additional characters for interoperability with older character encoding, and characters with control-like functions included primarily for reasons of providing unambiguous interpretation of plain text. Unicode provides specifications for the use of all of these characters.

 

Internationalization

 

The AdventNet Bean Builder supports Internationalization . The option to internationalize the project by generating the internationalized source is found in the "Project Properties" form in the "Source Generation " tab.

 

 

Internationalize the Source : This option is provided to internationalize the source generated. If you wish to internationalize the source check the option and provide the required details in the Locale Properties dialog. The Locale Properties dialog is invoked when you click the Locale Properties Button.

 

Locale

 

The locale is a file that has a mapping of  the words in one language on the left hand side to the words of the other language in the right-hand side.

 

Resource Bundle

 

Resource bundles contain locale-specific objects. When your program needs a locale-specific resource, a String for example, your program can load it from the resource bundle that is appropriate for the current user's locale. In this way, you can write program code that is largely independent of the user's locale isolating most, if not all, of the locale-specific information in resource bundles. The method getBundle() locates the locale file. The method getString() gives the mapping from English to the new language.

 

One resource bundle is, conceptually, a set of related classes that inherit from ResourceBundle. Each related subclass of ResourceBundle has the same base name plus an additional component that identifies its locale. For example, suppose your resource bundle is named as MyResources then the class you are likely to write first is the default resource bundle, which simply has the same name as its family--MyResources. You can also provide as many related locale-specific classes as you need. For example, perhaps you would provide a German one named MyResources_de.

 

If there are different resources for different countries, you can make specializations. For example, MyResources_de_CH is the German language (de) in Switzerland (CH). If you want to modify some of the resources in the specialization, you can do so.

 

How to Internationalize the Source

 

To internationalize the source, go to Project Properties in the "Properties Menu" . Select the "Source Generation" tab and  select the CheckBox corresponding to "Internationalize the Source". You will find a button by name "Locale Properties" alongside. Clicking it brings up a dialog that has a combo box which has the list of locales. Select the required Locale, click the "OK" button and then close the "Project Properties" window.

 

 

Click on "Regenerate" menu item under the "Build" menu of the tool for internationalization setting to take effect. The selected value for the Locale is set as a Project Parameter which is available in Project Properties in the 'General' Tab.

 

The two parameters related to Internationalization are

 

RESOURCE_PROPERTIES that represents the Bundle Name and

RESOURCE_LOCALE that represents the Locale.

 

By making the required changes either in the Project Parameters or in the Locale Properties Dialog the generated source can be internationalized.

 

Variable Name

 

The source will be generated with the variable name as shown below. By default it is set as "resourceBundle", it can be changed as desired by the user

 

For E.g., if the variable name is not changed then the source corresponding to internationalizing a JButton text will be

 

// JButton1.setText(resourceBundle.getString("OK"));

 

Bundle Name

 

The user can specify his resourceBundle name here. By default it is <ProjectName>Resources.

 

Locale

 

It helps to determine for which language the source is being generated. Suppose the user wants the application in a particular language, he can select the language from the combobox. Then the Resource bundle is named with the language extension. For example,

 

<ProjectName>Resources_ar_DZi  corresponding to the ar_DZi Locale.

 

Editing the locale file

 

The locale file is <ProjectName>Resources.properties . So, if the name of the project is "default", the name of the locale file is defaultResources.properties. The <ProjectName>ResourcesEditable.properties and the <ProjectName>Resources.properties can be found in the classes directory of your project (i.e. in the <Web NMS Home>/projects/<ProjectName>/classes) directory. The <ProjectName>ResourcesEditable.properties file is created with the English characters on the left side followed by a "=" and then the same characters in English as default. The user should open the <ProjectName>ResourcesEditable.properties file and enter the required language characters in the right hand side. Then the source has to be regenerated using the Build --> Regenerate menu item. When a regenerate is performed , the "native2ascii" command is executed and the UNICODE version of the characters is entered in the right hand side of the <ProjectName>Resources.properties file. Now, if the user Compiles the application and tests it, he can find the application in the specified language.

 

native2ascii tool

 

The purpose of native2ascii tool is to generate Unicode characters for a given set of characters in a file. To support intenationalization java expects all characters to be in Unicode format in the properties file. If the user is writing a locale for JAPANESE properties file, then he cannot type in the Unicode values for each and every Japanese character. So what the Bean Builder does is that it allows the user to enter his own Locale properties in a file called <ProjectName>ResourcesEditable.properties. Using the native2ascii tool provided in the JDK the values in the <ProjectName>ResourcesEditable.properties file are converted to <ProjectName>Resources.properties. This tool is run internally by the builder especially after each and every time the user regenerates the source. So after editing the <ProjectName>ResourcesEditable.properties file, the user has to go and regenerate the source to execute this native2ascii tool.

 

Example

 

 

The above illustration thus explains about internationalizing the Bean Builder project.



Copyright © 2011 ZOHO Corp. All Rights Reserved.