Preference Object-based Internationalization for

74 Slides1.46 MB

Preference Object-based Internationalization for Distributed Application Framework in Java Kenya Ishimoto [email protected] Yamato Software Laboratory IBM Japan, Ltd. 18th International Unicode Conference Hong Kong, April 2001

Agenda Introduction Requirements for Internationalization Difficulties with JDK Approach Conclusion Q&A 18th International Unicode Conference 2 Hong Kong, April 2001

Introduction 18th International Unicode Conference Hong Kong, April 2001

Tivoli Systems - background information an IBM company dedicated to providing products, services, and programs that enable companies of any size to manage their networked PCs and distributed systems from a single location. 18th International Unicode Conference 4 Hong Kong, April 2001

Tivoli Application Framework Distributed Used in the global company – multi-lingual – multi-culture Multiple-platform CORBA, XML Java UTF-8 Component-base Tivoli Console for applications to interact users 18th International Unicode Conference 5 Hong Kong, April 2001

Tivoli Console Example 18th International Unicode Conference 6 Hong Kong, April 2001

Agenda Introduction Requirements for Internationalization 1. Global multi-user support 2. Multiple locales for a single user 3. End-user Customization 4. Advanced Features Difficulties with JDK Approach Conclusion Q&A 18th International Unicode Conference 7 Hong Kong, April 2001

Requirements for Internationalization 18th International Unicode Conference Hong Kong, April 2001

Req.1: Global multi-user support Support multiple users simultaneously across different locales and time zones Locale fr FR Locale en US TimeZone Paris Locale zn HK TimeZone CST TimeZone Hong Kong 18th International Unicode Conference 9 Hong Kong, April 2001

Req.2: Multiple locales for a single user Allow user to select different locales for resource lookup and cultural conventions Locale fr FR Locale en US TimeZone Paris Locale zn HK for language TimeZone CST Locale en GB for cultural conventions TimeZone Hong Kong Tivoli provides English 9 translated language resources JDK can support more for cultural conventions. User can select them. 18th International Unicode Conference 10 Hong Kong, April 2001

Req.2: Multiple locales for a single user Locale constructor Locale(String language, String country) Locale loc new Locale(“fr”, “FR”); // French (France) Locale loc new Locale(“el”, “GR”); // Greek (Greece) Locale loc new Locale(“fr”, “GR”); // French (Greece) ? 18th International Unicode Conference 11 Hong Kong, April 2001

Req.3: End-user Customization Allow user to override a locale’s default attributes – e.g. date format styles and symbols The preferred non-default style should be persisted and to be used for future session, by all framework applications 18th International Unicode Conference 12 Hong Kong, April 2001

Req.4: Advanced features More features than the JDK – Multi-cultural calendar (Gregorian, Buddhist, Japanese, Hebrew, Islamic, Chinese) – Some other requirements are being discussed for future release. For example, transliteration, Java input method editor, etc. 18th International Unicode Conference 13 Hong Kong, April 2001

Agenda Introduction Requirements for Internationalization Difficulties with JDK – JDK’s Internationalization API – Example Approach Conclusion Q&A 18th International Unicode Conference 14 Hong Kong, April 2001

Difficulties with JDK 18th International Unicode Conference Hong Kong, April 2001

JDK’s Internationalization API Rich features, highly customizable Locale-sensitive classes in – java.util package – java.text package – etc. One default locale can be set 18th International Unicode Conference 16 Hong Kong, April 2001

Example: set default locale // set default locale Locale.setDefault(aLocale); 18th International Unicode Conference 17 Hong Kong, April 2001

Example 1: format a date // everything is based on the default locale DateFormat df DateFormat.getDateTimeInstance(); String dateDisplay sdf.format(aDate); 18th International Unicode Conference 18 Hong Kong, April 2001

Example 1: format a date // use cultLocale DateFormat df DateFormat.getDateTimeInstance( DateFormat.getDateTimeInstance(); DateFormat.DEFAULT, String dateDisplay sdf.format(aDate); DateFormat.DEFAULT, cultLocale); String dateDisplay sdf.format(aDate); 18th International Unicode Conference 19 Hong Kong, April 2001

Example 1: format a date // use cultLocale, dateTimePattern DateFormat df DateFormat.getDateTimeInstance(DateFormat.DEFAULT, DateFormat.DEFAULT, cultLocale); SimpleDateFormat (SimpleDateFormat)df; String dateDisplay sdf sdf.format(aDate); sdf.applyPattern(dateTimePattern); String dateDisplay sdf.format(aDate); 18th International Unicode Conference 20 Hong Kong, April 2001

Example 1: format a date // use cultLocale, dateTimePattern, ampmStr DateFormat df DateFormat.getDateTimeInstance(DateFormat.DEFAULT, DateFormat.DEFAULT, cultLocale); SimpleDateFormat sdf (SimpleDateFormat)df; sdf.applyPattern(dateTimePattern); DateFormatSymbols dfs sdf.getDateFormatSymbols(); String dateDisplay sdf.format(aDate); dfs.setAmPmStrings(ampmStr); sdf.setDateFormatSymbols(dfs); String dateDisplay sdf.format(aDate); 18th International Unicode Conference 21 Hong Kong, April 2001

Example 1: format a date // use cultLocale, dateTimePattern, ampmStr, timeZoneID TimeZone tz TimeZone.getTimeZone(timeZoneID); Calendar cal Calendar.getInstance(tz, cultLocale); DateFormat df DateFormat.getDateTimeInstance(DateFormat.DEFAULT, DateFormat.DEFAULT, cultLocale); df.setCalendar(cal);sdf (SimpleDateFormat)df; SimpleDateFormat sdf.applyPattern(dateTimePattern); SimpleDateFormat sdf (SimpleDateFormat)df; DateFormatSymbols dfs sdf.getDateFormatSymbols(); sdf.applyPattern(dateTimePattern); dfs.setAmPmStrings(ampmStr); DateFormatSymbols dfs sdf.getDateFormatSymbols(); sdf.setDateFormatSymbols(dfs); dfs.setAmPmStrings(ampmStr); sdf.setDateFormatSymbols(dfs); String dateDisplay sdf.format(aDate); String dateDisplay sdf.format(aDate); 18th International Unicode Conference 22 Hong Kong, April 2001

Example 2: format a message // use everything langLocale, is based cultLocale, on the default dateTimePattern, locale ampmstr, timeZoneID TimeZone tz TimeZone.getTimeZone(timeZoneID); Calendar cal Calendar.getInstance(tz, cultLocale); DateFormat df DateFormat.getDateTimeInstance(DateFormat.DEFAULT, DateFormat.DEFAULT, cultLocale); df.setCalendar(cal); SimpleDateFormat ResourceBundle rb sdf ResourceBundle.getBundle("MessageResources”); (SimpleDateFormat)df; sdf.applyPattern(dateTimePattern); String msgPattern rb.getString(MessageResources.MSG0001); DateFormatSymbols MessageFormat mf dfs new sdf.getDateFormatSymbols(); MessageFormat(msgPattern); dfs.setAmPmStrings(ampmStr); String msg mf.format(new Object[] {aDate}); sdf.setDateFormatSymbols(dfs); ResourceBundle rb ResourceBundle.getBundle("MessageResources", ResourceBundle.getBundle("MessageResources” langLocale); ); String msgPattern rb.getString(MessageResources.MSG0001); MessageFormat mf new MessageFormat(msgPattern); mf.setLocale(cultLocale); mf.applyPattern(msgPattern); mf.setFormat(0, sdf); String msg mf.format(new Object[] {aDate}); 18th International Unicode Conference 23 Hong Kong, April 2001

How can we . . . fulfill requirements for internationalization and keep application’s code simple as much as possible and keep consistent result across various applications on the framework? 18th International Unicode Conference 24 Hong Kong, April 2001

Agenda Introduction Requirements for Internationalization Difficulties with JDK Approach – Use of ICU4J – Low-level Internationalization API – High-level Framework Service Conclusion Q&A 18th International Unicode Conference 25 Hong Kong, April 2001

Approach 18th International Unicode Conference Hong Kong, April 2001

Hierarchy of Internationalization APIs Application (Tivoli Products) UI Lib. JDK Locale Sensitive Classes ICU4J ICU4J: International Components for Unicode for Java 18th International Unicode Conference 27 Hong Kong, April 2001

Use of ICU4J ICU4J is . . . International Components for Unicode for Java IBM’s open source project Java classes for internationalization in Unicode – – – – – – – International Calendars Unicode Normalization Number Format Enhancements Enhanced word-break detection Unicode Text Searching Unicode Text Compression etc. http://oss.software.ibm.com/developerworks/opensource/icu4j/ 18th International Unicode Conference 28 Hong Kong, April 2001

Hierarchy of Internationalization APIs Application (Tivoli Products) UI Lib. Low-level Internationalization API JDK Locale Sensitive Classes ICU4J ICU4J: International Components for Unicode for Java 18th International Unicode Conference 29 Hong Kong, April 2001

Agenda Introduction Requirements for Internationalization Difficulties with JDK Approach – Use of ICU4J – Low-level Internationalization API International Preference Object JDK/ICU4J Wrapper Other classes Rewrite Example – High-level Framework Service Conclusion Q&A 18th International Unicode Conference 30 Hong Kong, April 2001

International Preference Object Encapsulates user’s internationalization preferences – Language (Locale for resource lookup, HelpSet access, etc.) – Region (Locale for data formatting, etc.) – Calendar Type (Gregorian, Buddhist, Japanese, Islamic, Hebrew, Chinese) – Time Zone – Default override for Number format patterns and symbols – Default override for Date/Time format patterns and symbols All low-level API work with this object 18th International Unicode Conference 31 Hong Kong, April 2001

Setters on IntlPreferences Class setLanguageLocale setCulturalConventionLocale setTimeZone setCalendarType setDefaultDateStyle setDatePattern setDefaultTimeStyle setTimePattern setDateTimeOrder setDateTimeSeparator setAMString setPMString 18th International Unicode Conference setNumberPattern setCurrencyPattern setPercentPattern setGroupingSeparator setDecimalSeparator setPercent setZeroDigit setMinusSign setCurrencySymbol setInternationalCurrencySymbol setMonetaryDecimalSeparator 32 Hong Kong, April 2001

Hierarchy of Internationalization APIs Application (Tivoli Products) UI Lib. Low-level Internationalization API JDK Locale Sensitive Classes International Preference-based API 18th International Unicode Conference ICU4J ICU4J: International Components for Unicode for Java 33 Hong Kong, April 2001

Agenda Introduction Requirements for Internationalization Difficulties with JDK Approach – Use of ICU4J – Low-level Internationalization API International Preference Object JDK/ICU4J Wrapper Other classes Rewrite Example – High-level Framework Service Conclusion Q&A 18th International Unicode Conference 34 Hong Kong, April 2001

JDK/ICU4J Wrapper Purpose: Extend locale-based API to the international preferences object-based API Add one layer on ICU4J to avoid side effects of possible API changes 18th International Unicode Conference 35 Hong Kong, April 2001

JDK/ICU4J Wrapper Classes com.tivoli.intl java.util com.ibm.util com.tivoli.intl java.text com.ibm.text IntlDateFormat DateFormat SimpleDateFormat IntlSimpleDateFormat DateFormatSymbols IntlDateFormatSymbols NumberFormat IntlNumberFormat DecimalFormat IntlDecimalFormat DecimalFormatSymbols IntlDecimalFormatSymbols MessageFormat IntlMessageFormat IntlTimeZone TimeZone SimpleTimeZone IntlSimpleTimeZone IntlCalendar Calendar IntlGregorianCalendar GregorianCalendar BuddhistCalendar IntlBuddhistCalendar JapaneseCalendar IntlJapaneseCalendar HebrewCalendar IntlHebrewCalendar IslamicCalendar IntlIslamicCalendar ChineseCalendar IntlChineseCalendar 18th International Unicode Conference 36 Hong Kong, April 2001

JDK/ICU4J Wrapper Class Example java.text.DateFormat class (JDK) com.ibm.text.DateFormat class (ICU4J) public static DateFormat getDateInstance() public static DateFormat getDateInstance(int style) public static DateFormat getDateInstance(int style, Locale locale) com.tivoli.intl.IntlDateFormat class (Tivoli Wrapper) public static IntlDateFormat getDateInstance() public static IntlDateFormat getDateInstance(int style) public static IntlDateFormat getDateInstance(int style, Locale locale) public static IntlDateFormat getDateInstance(IntlPreferences ip) 18th International Unicode Conference 37 Hong Kong, April 2001

Other Classes com.tivoli.intl IntlPreferences IntlUtilities IntlDisplayableText IntlBundleLoader 18th International Unicode Conference 38 Hong Kong, April 2001

Agenda Introduction Requirements for Internationalization Difficulties with JDK Approach – Use of ICU4J – Low-level Internationalization API International Preference Object JDK/ICU4J Wrapper Other classes Rewrite Example – High-level Framework Service Conclusion Q&A 18th International Unicode Conference 39 Hong Kong, April 2001

Example 1: format a date // use cultLocale, dateTimePattern, ampmStr, timeZoneID TimeZone tz TimeZone.getTimeZone(timeZoneID); Calendar cal Calendar.getInstance(tz, cultLocale); DateFormat df DateFormat.getDateTimeInstance(DateFormat.DEFAULT, DateFormat.DEFAULT, cultLocale); df.setCalendar(cal); SimpleDateFormat sdf (SimpleDateFormat)df; sdf.applyPattern(dateTimePattern); DateFormatSymbols dfs sdf.getDateFormatSymbols(); dfs.setAmPmStrings(ampmStr); sdf.setDateFormatSymbols(dfs); String dateDisplay sdf.format(aDate); 18th International Unicode Conference 40 Hong Kong, April 2001

Example 2: format a message // use langLocale, cultLocale, dateTimePattern, ampmstr, timeZoneID TimeZone tz TimeZone.getTimeZone(timeZoneID); Calendar cal Calendar.getInstance(tz, cultLocale); DateFormat df DateFormat.getDateTimeInstance(DateFormat.DEFAULT, DateFormat.DEFAULT, cultLocale); df.setCalendar(cal); SimpleDateFormat sdf (SimpleDateFormat)df; sdf.applyPattern(dateTimePattern); DateFormatSymbols dfs sdf.getDateFormatSymbols(); dfs.setAmPmStrings(ampmStr); sdf.setDateFormatSymbols(dfs); ResourceBundle rb ResourceBundle.getBundle("MessageResources", langLocale); String msgPattern rb.getString(MessageResources.MSG0001); MessageFormat mf new MessageFormat(msgPattern); mf.setLocale(cultLocale); mf.applyPattern(msgPattern); mf.setFormat(0, sdf); String msg mf.format(new Object[] {aDate}); 18th International Unicode Conference 41 Hong Kong, April 2001

Rewrite examples: Customization // Customizations are centralized to the International preferences ip.setLanguageLocale(langLocale); ip.setCulturalConventionLocale(cultLocale); ip.setTimeZone(timeZoneID); ip.setAMString(ampmStr[0]); ip.setPMString(ampmStr[1]); ip.setDatePattern(datePattern, IntlPreferences.MEDIUM); ip.setTimePattern(timePattern, IntlPreferences.MEDIUM); ip.setDateTimeOrder(IntlPreferences.DATE FIRST); . ( . . . 23 setters can be used ) 18th International Unicode Conference 42 Hong Kong, April 2001

Rewrite example 1: format a date // everything is based on the default locale DateFormat df DateFormat.getDateTimeInstance(); String dateDisplay df.format(aDate); // use international preferences IntlDateFormat df IntlDateFormat.getDateTimeInstance(ip); String dateDisplay df.format(aDate); 18th International Unicode Conference 43 Hong Kong, April 2001

Rewrite example 2: format a message // everything is based on the default locale ResourceBundle rb ResourceBundle.getBundle("MessageResources"); String msgPattern rb.getString(MessageResources.MSG0001); MessageFormat mf new MessageFormat(msgPattern); String msg mf.format(new Object[] {aDate}); // use international preferences ResourceBundle rb IntlUtilities.getBundle(ip, "MessageResources"); String msgPattern rb.getString(MessageResources.MSG0001); IntlMessageFormat mf new IntlMessageFormat(ip, msgPattern); String msg mf.format(new Object[] {aDate}); 18th International Unicode Conference 44 Hong Kong, April 2001

Agenda Introduction Requirements for Internationalization Difficulties with JDK Approach – Use of ICU4J – Low-level Internationalization API – High-level Framework Service Layer Separation High-level Framework Service Rewrite Example International Preferences Notebook Example Conclusion Q&A 18th International Unicode Conference 45 Hong Kong, April 2001

Hierarchy of Internationalization APIs Application (Tivoli Products) High-level International Service UI Lib. Low-level Internationalization API JDK Locale Sensitive Classes International Preference-based API 18th International Unicode Conference ICU4J ICU4J: International Components for Unicode for Java 46 Hong Kong, April 2001

Layer Separation High-level International Service Include the framework specific implementations Correlate application’s context to the user’s international preference Be generic for reusability Take international preference object from method argument Low-level Internationalization API 18th International Unicode Conference 47 Hong Kong, April 2001

Agenda Introduction Requirements for Internationalization Difficulties with JDK Approach – Use of ICU4J – Low-level Internationalization API – High-level Framework Service Layer Separation High-level Framework Service Rewrite Example International Preferences Notebook Example Conclusion Q&A 18th International Unicode Conference 48 Hong Kong, April 2001

High-level International Service One of the services for the framework applications Provides a set of convenience methods on top of low-level internationalization API Manages the international preferences object according to the application context The preferences object is persisted using a framework service. 18th International Unicode Conference 49 Hong Kong, April 2001

Hierarchy of Internationalization APIs Application (Tivoli Products) High-level International Service UI Lib. preference Low-level Internationalization API JDK Locale Sensitive Classes International Preference-based API 18th International Unicode Conference ICU4J ICU4J: International Components for Unicode for Java 50 Hong Kong, April 2001

Methods on International Service com.tivoli.pf.fmk.external.IFmkIntlService Resource Loading Collator Factory Method – getCollator – getBundle, getString, getObject Date Formatting BreakIterator Factory Method – getCharacterBreakIterator, getWordBreakIterator, getLineBreakIterator, getSentenceBreakIterator – formatDate, formatTime, formatDateTime, parseDate, parseTime, parseDateTime Number Formatting – formatNumber, formatCurrency, formatPercent, parseNumber, parseCurrency, parsePercent Case Conversion / Comparison – toLowerCase, toUpperCase, equalsIgnoreCase Message Formatting Late-binding Text Resolution – getDisplayText – formatMessage, parseMessage IntlPreferences Access – getIntlPreferences 18th International Unicode Conference 51 Hong Kong, April 2001

Agenda Introduction Requirements for Internationalization Difficulties with JDK Approach – Use of ICU4J – Low-level Internationalization API – High-level Framework Service Layer Separation High-level Framework Service Rewrite Example International Preferences Notebook Example Conclusion Q&A 18th International Unicode Conference 52 Hong Kong, April 2001

Rewrite example 1: format a date // everything is based on the default locale DateFormat df DateFormat.getDateTimeInstance(); String dateDisplay df.format(aDate); // works according to the user’s international preferences String dateDisplay intlService.formatDate(aContext, aDate); 18th International Unicode Conference 53 Hong Kong, April 2001

Rewrite example 2: format a message // everything is based on the default locale ResourceBundle rb ResourceBundle.getBundle("MessageResources"); String msgPattern rb.getString(MessageResources.MSG0001); MessageFormat mf new MessageFormat(msgPattern); String msg mf.format(new Object[] {aDate}); // works according to the user’s international preferences String msg intlService.getString(aContext, "MessageResources", MessageResources.MSG0001, new Object[] {aDate}); 18th International Unicode Conference 54 Hong Kong, April 2001

Agenda Introduction Requirements for Internationalization Difficulties with JDK Approach – Use of ICU4J – Low-level Internationalization API – High-level Framework Service Layer Separation High-level Framework Service Rewrite Example International Preferences Notebook Example Conclusion Q&A 18th International Unicode Conference 55 Hong Kong, April 2001

International Preference Notebook 18th International Unicode Conference 56 Hong Kong, April 2001

Preference Notebook Preview Example Region: Style: Calendar: Time Zone: US Medium Gregorian CST 18th International Unicode Conference 57 Hong Kong, April 2001

Preference Notebook Preview Example Region: Style: Calendar: Time Zone: France Medium Gregorian Paris 18th International Unicode Conference 58 Hong Kong, April 2001

Preference Notebook Preview Example Region: Style: Calendar: Time Zone: Japan Full Japanese-era Tokyo 18th International Unicode Conference 59 Hong Kong, April 2001

Agenda Introduction Requirements for Internationalization Difficulties with JDK Approach – Use of ICU4J – Low-level Internationalization API – High-level Framework Service Layer Separation High-level Framework Service Rewrite Example International Preferences Notebook Example Conclusion Q&A 18th International Unicode Conference 60 Hong Kong, April 2001

Example – Message Dialog Language: Region: English US 18th International Unicode Conference 61 Hong Kong, April 2001

Example – Message Dialog Language: Region: Simplified Chinese US 18th International Unicode Conference 62 Hong Kong, April 2001

Example – Message Dialog Language: Region: French France 18th International Unicode Conference 63 Hong Kong, April 2001

Example – Message Dialog Language: Region: French Greece 18th International Unicode Conference 64 Hong Kong, April 2001

Example – Message Dialog Language: Region: Calendar: Japanese Japan Japanese 18th International Unicode Conference 65 Hong Kong, April 2001

Agenda Introduction Requirements for Internationalization Difficulties with JDK Approach Conclusion – For Requirements 1. 2. 3. 4. Global multi-user support Multiple locales for a single user End-user Customization Advanced Features – Benefits Q&A 18th International Unicode Conference 66 Hong Kong, April 2001

Conclusion 18th International Unicode Conference Hong Kong, April 2001

For req.1: Global multi-user support In high-level international service layer, the user’s locale and time zone is managed according to the application context. Each user’s preference settings are persistent across the network. 18th International Unicode Conference 68 Hong Kong, April 2001

For req.2: Multiple locales for a single user Multiple locales are encapsulated in the international preferences object. Low-level API uses appropriate locale from the preferences object. 18th International Unicode Conference 69 Hong Kong, April 2001

For req.3: End-user Customization Various attributes for customization encapsulated in an object. It simplifies API usage. User can alter the object through preference notebook GUI. 18th International Unicode Conference 70 Hong Kong, April 2001

For req.4: Advanced features Multi-cultural calendar systems are supported ICU4J is used as core internationalization API. More feature will be used in the future releases. 18th International Unicode Conference 71 Hong Kong, April 2001

Benefits for end-users Flexible customization Functionality for multiple-locale Consistent presentation 18th International Unicode Conference 72 Hong Kong, April 2001

Benefits for application developer High-level International Service can be used as a single point to provide internationalization API Various internationalization attributes are encapsulated into an object to make API usage simple International preference-based Swing widgets 18th International Unicode Conference 73 Hong Kong, April 2001

Questions & Answers 18th International Unicode Conference Hong Kong, April 2001

Back to top button