SCEA之路--9. INTERNATIONALIZATION

来源:互联网 发布:java frame text 编辑:程序博客网 时间:2024/05/21 11:14

General.
Internationalisation.
An application with support for Internationalisation
• a.k.a. I18N
• can be adapted to other languages / regions
• process is quick and easily
• doesn’t require engineering / code changes to add support for another language / region (dependencies are stored externally)
Localisation.
• a.k.a. L10N
• addition of language dependent components
• translation of text, etc.

Considerations for I18N applications.
• common text output (text, dates, times, currency, numbers)
• other text output (measurements, phone numbers, postcodes, titles)
• GUI items (labels, buttons, menus, etc.)
• media (graphics, sounds, icons)

State Three Aspects of any Application That Might Need to Be Varied or Customized in Different Deployment Locales
• Presentation of text, dates, numbers
• Labels on presentation components
• Sounds
• Colors
• Images or Icons
• Input and output routines that read and write text files
• Collation or ordering of data presented in a list

List Three Features of the Java Programming Language That Can Be Used to Create an Internationalizable/Localizable Application
• java.util.Properties for obtaining localized values using the same key
• java.text.NumberFormat to handle numbers and currencies
• java.text.DateFormat to handle date and time
• java.text.Collator and java.text.CollationKey for ordering data
• java.text.MessageFormat, java.util.ResourceBundle, or java.util.PropertyResourceBundle to handle text
• java.io.InputStreamReader and java.io.OutputStreamWriter for reading and writing files
• java.util.Locale and contentType and pageEncoding attributes for JSPs
• java.util.Locale and ServletResponse.setContentType() and ServletResponse.setLocale() methods for servlets

Java I18N classes.
java.util.Locale
• combination of language and country – e.g. locale = new Locale("en", "GB");
• locale-aware classes can be locale instance based but otherwise default to the JVM locale
• can also construct with a variant – e.g. locale = new Locale("en", "GB", “UNIX”);

java.util.ResourceBundle
• acts as a container for locale specific properties
• ResourceBundle.getBundle (NAME, LOCALE) will scan for a class or property file matching NAME_LANGUAGE-CODE_COUNTRY-CODE (e.g. Test_en_GB.class or Test_en_GB.properties)
• ResourceBundle accessors – getString (NAME), getObject (NAME)
• two subclasses available – PropertyResourceBundle and ListResourceBundle
• PropertyResourceBundle (dependencies defined as Strings in a property file)
• ListResourceBundle (dependencies defined as Objects in a subclass of istResourceBundle)

java.text.NumberFormat
• Provides support for parsing/formatting numbers, currency and percentages in a locale-specific
manner using pre-defined patterns
• NumberFormat.getNumberInstance (LOCALE).format (NUM)
• NumberFormat.getCurrencyInstance (LOCALE).format (NUM)
• NumberFormat.getPercentageInstance (LOCALE).format (NUM)

java.text.DecimalFormat
• Provides support for custom parsing/formatting of numbers using format patterns
• ‘#’ is used to specify digits, ‘,’ for grouping and ‘.’ for decimal points
• ‘0’ is used to specify digits with leading zeros
• “123456.789” with pattern of “0000,###.## “ results in “0123,456.79”
• output symbols can be changed – e.g. ‘.’ can be rendered as any requested character

java.text.DateFormat
• Provides support for parsing/formatting dates and times in a locale-specific manner using predefined patterns. Len of output can be controlled – e.g. DEFAULT, SHORT, MEDIUM, LONG, FULL
• DateFormat.getDateInstance (DateFormat.DEFAULT, LOCALE).format (DATE)
• DateFormat.getTimeInstance (DateFormat.DEFAULT, LOCALE).format (DATE)
• df.getDateTimeInstance (DateFormat.DEFAULT, DateFormat.DEFAULT, LOCALE).format (DATE)

java.text.SimpleDateFormat
• Provides support for custom parsing/formatting of dates/times using format patterns
• E.g. pattern “dd/MM/yy HH:mm:ss” results in “06/03/02 02:06:30”
• for correct rendering of dates and times, use locale + pattern (pattern on it’s own could leads to
inconsistent formatting in other languages)
• date symbols can be changed (e.g. “Mon” can be changed to “MON”)

java.text.MessageFormat
• provides support for template based rendering in a locale-specific manner using a pattern string and an array of arguments – similar to placeholders in SQL PreparedStatement

java.text.BreakIterator
• provides support for identifying breaks (by character, word, sentence or line) in text in a localespecific manner
• getCharacterInstance (), getWordInstance (), getSentenceInstance (), getLineInstance ()
• BreakIterator.first (), BreakIterator.next (), while (BreakIterator.next () != BreakIterator.DONE)

原创粉丝点击