General.Internationalisation.An application with support for Internationalisation • aka I18N • can be adapted to other languages / regions • process is quick and easily • does not require engineering / code changes to add support for another language / region (dependencies are stored externally ) Localisation. • AKA 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 Order 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 - eg 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 - eg 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 (eg 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-specificmanner 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, ###. ## "RESUTS IN" 0123, 456.79 "• Output Symbols Can Be Changed - EG '.' 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 -. eg 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 • Eg 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 Toinconsistent Formatting in Other Languages) • Date Symbols Can Be Changed (EG "MON" can be be changing to "mon")
Java.Text.MessageFormat • Province 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 (BreakItemrator.next ()! = BreakItem.done)