★ wanayoo — archive 1999 http://ibm.com/java/education/international-unicode/unicode2.9.htmlNouvelle recherche | Portail wanayoo

Introduction to IBM Classes for Unicode


2.9 Handle Multilingual Text

If you wish, you can go further and support a multilingual application (or applet), which allows use of simultaneous multiple locales. First you should understand an important distinction between multilingual data and multilingual user interface:

  • multilingual data: Users can enter data or set data formats according to multiple locales (e.g. formats of cells in a spreadsheet).
  • multilingual user interface: Users can switch the locale of the display of your application (Menus, Buttons, etc.) at runtime.

Since Unicode is the character set for Java, and the one used by the C/C++ Iibraries, the user can enter in multilingual data (with some restrictions; see ICU 1.0 locales). All of the formats, collators, and other international classes allow you to pass an explicit Locale as a parameter. You can thus give the user the choice of which locales to use for your display locale or for data. This allows you, for example, to easily have French dates in one column of a table and German dates in another.

Although for most applications a runtime multilingual user interface is not worth the effort, if you do want to support it, you will restructure your application somewhat. Essentially, you must do one of the following:

  • Separate out the code that builds your UI. When the user picks a different UI locale from a menu, you reset the default locale and then simply call your code to rebuild the whole UI.
  • Provide code that walks through your UI. When the user picks a different UI locale from a menu, you reset the default locale and call this code to go through each menu and container to replace each individual element with the appropriate new resources.

Multilingual Text Handling

Java

NumberFormat numFmt = NumberFormat.getInstance(Locale.FRANCE);

C++

NumberFormat numFmt = NumberFormat.createInstance(Locale::FRANCE);

C

NumberFormat* numFmt = T_NumberFormat_createInstance(T_Locale_FRANCE());

 

 

To find out the list of locales available for a particular type of object, such as a NumberFormat, look for a static on that object (or its base class) called getAvailableLocales(). To then display the localized names of those locales, such as in a Menu or List, use getDisplayName().

 

Listing Locales

Java

Locale[] locales = NumberFormat.getAvailableLocales(); 

for (int i = 0; i < locales.length; ++i) {

display(locales[i].getDisplayName()); 

}

C++

const Locale *locale = NumberFormat::getAvailableLocales(count); 
for (int i = 0; i < count; i++) { 

localeString = locale[i].getDisplayName(localeString);

display(localeString);

}

C

  

for (locale = T_NumberFormat_getAvailableLocales(0);locale != 0; count++) { 

locale = T_NumberFormat_getAvailableLocales(count); 

T_Locale_getDisplayName(locale, localeString);

display(localeString); 





JavaTM is a trademark of Sun Microsystems, Inc.

Microsoft is a registered trademark of Microsoft Corporation.

Other companies, products, and service names may be trademarks or service marks of others.

Copyright    Trademark



IBM HomeOrderEmployment