Globalizing Your Java Application Intertech’s Oxygen Blast Series September 2009
Introduction <ul><li>Jason S. Shapiro –  http://decoupledmusings.blogspot.com </li></ul><ul><li>~15 Years Professional Sof...
Agenda <ul><li>Globalization: Definition & Terms </li></ul><ul><li>Project Stages </li></ul><ul><ul><li>Internationalizati...
Agenda <ul><li>Internationalization (continued) </li></ul><ul><ul><li>Character Encoding </li></ul></ul><ul><ul><li>3 rd  ...
Available On Line <ul><li>Slides </li></ul><ul><ul><li>http://www.intertech.com/downloads/o2-i18n.pptx </li></ul></ul>
Globalization: Definition & Terms <ul><li>Globalization, in the context of software, denotes that an application has been ...
Globalization: Definition & Terms <ul><li>Localization (l10n) -  continued </li></ul><ul><ul><li>This is the process of cr...
Project Stages <ul><li>Internationalization </li></ul><ul><li>Create documentation for translation services </li></ul><ul>...
Internationalization (i18n) <ul><li>Identify content that should change depending on a user’s region. </li></ul><ul><li>Re...
i18n: Locales <ul><li>A “Locale” is a Java object that represents various types of information for a user or machine. </li...
i18n: Locales <ul><li>Language </li></ul><ul><ul><li>This is what people typically think of a locale representing. </li></...
i18n: Locales <ul><li>Country </li></ul><ul><ul><li>Initialized with an uppercase, two letter, ISO-3166 language code. </l...
i18n: Locales <ul><li>Variant </li></ul><ul><ul><li>A way to further differentiate the region or user for specialized disp...
i18n: Locales <ul><li>Out of these three properties, the following combinations are possible: </li></ul><ul><ul><li>A loca...
i18n: Locales <ul><li>In addition, the java.util.Locale class provides many static properties that are pre-configured Loca...
i18n: Locales <ul><li>Using Locale Objects </li></ul><ul><ul><li>Locale objects are created strictly to represent regions,...
i18n: Content <ul><li>Now that it has been established that Locales are used by other libraries, let’s focus on the types ...
i18n: Content <ul><li>Numbers / Currency </li></ul><ul><ul><li>Characters </li></ul></ul><ul><ul><li>Groupings and Delimit...
i18n: Content <ul><li>Dates / Times </li></ul><ul><ul><li>Language  </li></ul></ul><ul><ul><ul><li>Regional specific names...
i18n: Content <ul><li>Calendar Formatter Example </li></ul><ul><li>import java.text.DateFormat; </li></ul><ul><li>import j...
i18n: Content <ul><li>Number Formatter Example </li></ul><ul><li>import java.text.NumberFormat; </li></ul><ul><li>import j...
i18n: Resource Bundles <ul><li>Can either be a Java Class or a Property File </li></ul><ul><li>Naming Conventions </li></u...
i18n: Resource Bundles <ul><li>Three Different Types of Resource Bundles </li></ul><ul><ul><li>Class that extends java.uti...
i18n: Resource Bundles – Class Example import java.util.Enumeration; import java.util.Locale; import java.util.ResourceBun...
i18n: Resource Bundles – Class Example <ul><li>public class ResourceBundleExample_en extends ResourceBundleExample { </li>...
i18n: Resource Bundles – Class Example <ul><li>public class ResourceBundleExample_fr extends ResourceBundleExample { </li>...
i18n: Resource Bundles – Class Example <ul><li>import java.util.Locale; </li></ul><ul><li>import java.util.ResourceBundle;...
i18n: Resource Bundles – Property File Example # PropertyFileExample_en.properties username= Username   (prop   file) pass...
i18n: Resource Bundles – Property File Example <ul><li>import java.util.Locale; </li></ul><ul><li>import java.util.Resourc...
i18n: Resource Bundles – Parameter Example # PropertyFileExample_en.properties username= Username :  {0}   -   {1,date,lon...
i18n: Resource Bundles – Parameter Example MessageFormat parameters Time or Date : short, medium, long, full, pattern Numb...
i18n: Resource Bundles – Parameter Example <ul><li>import java.text.MessageFormat; </li></ul><ul><li>import java.util.*; <...
i18n: Resource Bundles – ListResourceBundle <ul><li>public class ListResourceBundleExample_en_US extends ListResourceBundl...
i18n: Resource Bundles – ListResourceBundle <ul><li>public class  ListResourceBundleTester extends JPanel { </li></ul><ul>...
i18n: Resource Bundles <ul><li>How is a resource bundle selected? </li></ul><ul><li>The submitted locale is inspected and ...
i18n: Resource Bundles <ul><li>Like the original submitted locale, it first tries to find a resource bundle that matches t...
i18n: Resource Bundles <ul><li>If nothing is found, a “MissingResource” exception is thrown. </li></ul><ul><li>Once a reso...
i18n: Resource Bundles Quiz <ul><li>ResourceBundleQuiz.properties </li></ul><ul><li>username=jason (base) </li></ul><ul><l...
i18n: Resource Bundles Quiz <ul><li>ResourceBundleQuiz.properties </li></ul><ul><li>username=jason (base) </li></ul><ul><l...
i18n: Resource Bundles Quiz <ul><li>ResourceBundleQuiz.properties </li></ul><ul><li>username=jason (base) </li></ul><ul><l...
i18n: Resource Bundles Quiz <ul><li>ResourceBundleQuiz.properties </li></ul><ul><li>username=jason (base) </li></ul><ul><l...
i18n: Resource Bundles Quiz <ul><li>ResourceBundleQuiz.properties </li></ul><ul><li>username=jason (base) </li></ul><ul><l...
i18n: Collation <ul><li>Different Regional / Language Rules </li></ul><ul><li>Multi-Character Contractions </li></ul><ul><...
i18n: Collation Collator collate = Collator.getInstance( myLocale ); collate.setStrength(Collator.IDENTICAL); Collections....
i18n: GUI Considerations <ul><li>Layout </li></ul><ul><ul><li>Different regions expect information to flow in different di...
i18n: GUI Considerations <ul><li>Character Expansion / Contraction </li></ul><ul><ul><li>Different languages may push out ...
i18n: Character Sets & Encoding <ul><li>Code Sets </li></ul><ul><ul><li>Each unique code represents a unique character </l...
i18n: Character Sets & Encoding <ul><li>Encoding </li></ul><ul><ul><li>Modal </li></ul></ul><ul><ul><ul><li>Escape charact...
i18n: Character Sets & Encoding <ul><li>Setting Encoding in Servlets </li></ul><ul><ul><li>response.setCharacterEncoding(&...
i18n: Third Party Tools <ul><li>IBM’s ICU4J </li></ul><ul><ul><li>http://site.icu-project.org/ </li></ul></ul><ul><li>JSTL...
i18n: Third Party Tools <ul><li>JSF Example </li></ul>// FacesConfig.xml <application> <locale-config> <default-locale>en_...
Localization (l10n) <ul><li>Submitting Resource Bundles </li></ul><ul><ul><li>Screenshots w/ functional descriptions </li>...
i18n / l10n Resources <ul><li>Deitsch, Andrew, and David Czarnecki.  Java Internationalization . Sebastopol: O'Reilly, 200...
Related Courses at Intertech <ul><li>Complete Java </li></ul><ul><ul><li>http://www.intertech.com/Courses/Course.aspx?Cour...
Intertech Resources <ul><li>Facebook </li></ul><ul><ul><li>http://facebook.intertech.com </li></ul></ul><ul><li>Twitter </...
What you have learned today <ul><li>Globalization: Definition & Terms </li></ul><ul><li>Project Stages </li></ul><ul><ul><...
What you have learned today <ul><li>Internationalization (continued) </li></ul><ul><ul><li>Character Encoding </li></ul></...
Intertech Resources <ul><li>Intertech offers free: </li></ul><ul><ul><li>Content packed newsletters </li></ul></ul><ul><ul...
Intertech Training <ul><li>Founded in 1991, Intertech offers a full training line-up: </li></ul><ul><ul><li>JEE, open sour...
Intertech Consulting <ul><li>In addition to training, Intertech delivers consulting </li></ul><ul><li>Consulting is part o...
Thank You! http://www.intertech.com
Upcoming SlideShare
Loading in...5
×

Globalizing Your Java Application Training

1,445

Published on

Globalization: Definition & Terms

Project Stages
Internationalization
Localization
Testing

Internationalization
Locales
Content
Resource Bundles
Collation
GUI Considerations

Published in: Technology, News & Politics
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
1,445
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
0
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Transcript of "Globalizing Your Java Application Training"

  1. 1. Globalizing Your Java Application Intertech’s Oxygen Blast Series September 2009
  2. 2. Introduction <ul><li>Jason S. Shapiro – http://decoupledmusings.blogspot.com </li></ul><ul><li>~15 Years Professional Software Development and Architecture Experience </li></ul><ul><li>Master of Science in Software Engineering </li></ul><ul><li>Sun Certified Java Programmer & Web Component Developer </li></ul><ul><li>Patent: “Web Portal Layout Manager System and Method” </li></ul>
  3. 3. Agenda <ul><li>Globalization: Definition & Terms </li></ul><ul><li>Project Stages </li></ul><ul><ul><li>Internationalization </li></ul></ul><ul><ul><li>Localization </li></ul></ul><ul><ul><li>Testing </li></ul></ul><ul><li>Internationalization </li></ul><ul><ul><li>Locales </li></ul></ul><ul><ul><li>Content </li></ul></ul><ul><ul><li>Resource Bundles </li></ul></ul><ul><ul><li>Collation </li></ul></ul><ul><ul><li>GUI Considerations </li></ul></ul>
  4. 4. Agenda <ul><li>Internationalization (continued) </li></ul><ul><ul><li>Character Encoding </li></ul></ul><ul><ul><li>3 rd Party Tools </li></ul></ul><ul><li>Localization </li></ul><ul><ul><li>Submitting Resource Bundles </li></ul></ul><ul><ul><li>Words vs. Context </li></ul></ul><ul><ul><li>Testing </li></ul></ul><ul><li>Questions / Open Discussion </li></ul>
  5. 5. Available On Line <ul><li>Slides </li></ul><ul><ul><li>http://www.intertech.com/downloads/o2-i18n.pptx </li></ul></ul>
  6. 6. Globalization: Definition & Terms <ul><li>Globalization, in the context of software, denotes that an application has been Internationalized and Localized </li></ul><ul><li>Internationalization (i18n) </li></ul><ul><ul><li>i18n – There are 18 letters in between the first ‘I’ and the final ‘N’ in the word “Internationalization” </li></ul></ul><ul><ul><li>This is the process of removing hard coded regional specific information from an application. </li></ul></ul><ul><li>Localization (l10n) </li></ul><ul><ul><li>l10n – There are 10 letters in between the first ‘L’ and the final ‘N’ in the word “Localization.” </li></ul></ul>
  7. 7. Globalization: Definition & Terms <ul><li>Localization (l10n) - continued </li></ul><ul><ul><li>This is the process of creating a set of resources (text, images, etc.) that are regionally based, and loaded into an Internationalized application. </li></ul></ul>
  8. 8. Project Stages <ul><li>Internationalization </li></ul><ul><li>Create documentation for translation services </li></ul><ul><li>Localization Testing </li></ul>
  9. 9. Internationalization (i18n) <ul><li>Identify content that should change depending on a user’s region. </li></ul><ul><li>Remove this content and place them into external resources </li></ul><ul><li>Use API methods to delegate the lookup and rendering of this content until runtime. </li></ul><ul><li>Internationalization does not mean your application supports more than one region – it means that all hard coded regional information has been extracted, and thus the source code does not need to be modified in order to support additional regions. </li></ul>
  10. 10. i18n: Locales <ul><li>A “Locale” is a Java object that represents various types of information for a user or machine. </li></ul><ul><li>This object is passed into internationalized components and used to make decisions about what type of material should be selected and displayed. </li></ul><ul><li>A locale can be built with three different properties: </li></ul><ul><ul><li>A language </li></ul></ul><ul><ul><li>A country </li></ul></ul><ul><ul><li>A variant </li></ul></ul>
  11. 11. i18n: Locales <ul><li>Language </li></ul><ul><ul><li>This is what people typically think of a locale representing. </li></ul></ul><ul><ul><li>Initialized with the lowercase, two letter, ISO-639-1 language code. </li></ul></ul><ul><ul><ul><li>Language code examples: </li></ul></ul></ul><ul><ul><ul><ul><li>en = English </li></ul></ul></ul></ul><ul><ul><ul><ul><li>de = German </li></ul></ul></ul></ul><ul><ul><ul><ul><li>es = Spanish </li></ul></ul></ul></ul><ul><ul><ul><li>There is a newer, three letter standard, known as ISO-639-2, but for compatibility with older components, it’s best to stick with the two letter standard/ </li></ul></ul></ul><ul><ul><ul><li>A list of current language codes (both 2 and 3 letter versions) can be found at: http://www.loc.gov/standards/iso639-2/php/English_list.php </li></ul></ul></ul>
  12. 12. i18n: Locales <ul><li>Country </li></ul><ul><ul><li>Initialized with an uppercase, two letter, ISO-3166 language code. </li></ul></ul><ul><ul><ul><li>Country code examples: </li></ul></ul></ul><ul><ul><ul><ul><li>US = United States </li></ul></ul></ul></ul><ul><ul><ul><ul><li>CA = Canada </li></ul></ul></ul></ul><ul><ul><ul><ul><li>IN= India </li></ul></ul></ul></ul><ul><ul><ul><li>A list of current country codes can be found at: http://www.iso.org/iso/country_codes/iso_3166_code_lists/english_country_names_and_code_elements.htm </li></ul></ul></ul>
  13. 13. i18n: Locales <ul><li>Variant </li></ul><ul><ul><li>A way to further differentiate the region or user for specialized displays </li></ul></ul><ul><ul><li>This is an arbitrary String of your choice – no ISO standards are required </li></ul></ul><ul><ul><li>Some common examples </li></ul></ul><ul><ul><ul><li>Differentiating between Windows (WIN) and Macintosh Users (MAC) </li></ul></ul></ul><ul><ul><ul><li>Add unique branding for different clients by specifying their company name (INTERTECH) </li></ul></ul></ul>
  14. 14. i18n: Locales <ul><li>Out of these three properties, the following combinations are possible: </li></ul><ul><ul><li>A locale with only the language code </li></ul></ul><ul><ul><li>A locale with a language and a geographical area code </li></ul></ul><ul><ul><li>A locale with a language, a geographical area, and a variant code. </li></ul></ul><ul><li>As such the java.util.Locale class provides the following three constructors: </li></ul><ul><li>Locale( String language ); </li></ul><ul><li>Locale( String language, String country ); </li></ul><ul><li>Locale( String language, String country, String variant ); </li></ul>
  15. 15. i18n: Locales <ul><li>In addition, the java.util.Locale class provides many static properties that are pre-configured Locale language or country objects: </li></ul><ul><ul><li>Locale.FRENCH // language </li></ul></ul><ul><ul><li>Locale.FRANCE // country </li></ul></ul><ul><ul><li>Locale.GERMAN // language </li></ul></ul><ul><ul><li>Locale.GERMANY // country </li></ul></ul>
  16. 16. i18n: Locales <ul><li>Using Locale Objects </li></ul><ul><ul><li>Locale objects are created strictly to represent regions, and don’t provide any specific translation or related functionality </li></ul></ul><ul><ul><li>Their actual usage is up to the developers of the libraries you are leveraging. </li></ul></ul><ul><ul><li>Typical use-case scenarios </li></ul></ul><ul><ul><ul><li>A date is formatted for a specific region, by passing a Locale object into a Time/Date formatters </li></ul></ul></ul><ul><ul><ul><li>A resource bundle is selected, containing text and images, based on a Locale </li></ul></ul></ul><ul><ul><ul><li>Sorting and searching is executed in a manner that reflects the rules of a region, by configuring a Collator with a Locale object. </li></ul></ul></ul>
  17. 17. i18n: Content <ul><li>Now that it has been established that Locales are used by other libraries, let’s focus on the types of information and functionality they provide: </li></ul><ul><li>Text </li></ul><ul><ul><li>Language Selection </li></ul></ul><ul><ul><li>Sorting & Searching </li></ul></ul><ul><ul><li>Text Direction </li></ul></ul><ul><ul><li>Word and Sentence Boundaries </li></ul></ul>
  18. 18. i18n: Content <ul><li>Numbers / Currency </li></ul><ul><ul><li>Characters </li></ul></ul><ul><ul><li>Groupings and Delimiters </li></ul></ul><ul><ul><ul><li>481,516.23 vs. 481.516,23 vs. 481 516,23 </li></ul></ul></ul><ul><ul><li>Symbols </li></ul></ul><ul><li>Images </li></ul>
  19. 19. i18n: Content <ul><li>Dates / Times </li></ul><ul><ul><li>Language </li></ul></ul><ul><ul><ul><li>Regional specific names of a month </li></ul></ul></ul><ul><ul><li>Formats </li></ul></ul><ul><ul><ul><li>MM/DD/YYYY vs DD/MM/YYYY </li></ul></ul></ul><ul><ul><li>Delimiter </li></ul></ul><ul><ul><ul><li>7/24/2009 vs 4-JUL-09 </li></ul></ul></ul><ul><ul><li>Regional Calendars </li></ul></ul><ul><ul><ul><li>Western Gregorian Calendar: September 10, 2009 </li></ul></ul></ul><ul><ul><ul><li>Hebrew Calendar: Elul 21, 5769 </li></ul></ul></ul><ul><ul><li>First Day of the Week </li></ul></ul><ul><ul><ul><li>England : Sunday </li></ul></ul></ul><ul><ul><ul><li>France : Monday </li></ul></ul></ul>
  20. 20. i18n: Content <ul><li>Calendar Formatter Example </li></ul><ul><li>import java.text.DateFormat; </li></ul><ul><li>import java.util.*; </li></ul><ul><li>public class CalendarExample { </li></ul><ul><li>public static void main(String[] args) { </li></ul><ul><ul><ul><li>Locale myLocale = new Locale(args[0]); </li></ul></ul></ul><ul><ul><ul><li>Calendar myCal = Calendar. getInstance(myLocale); </li></ul></ul></ul><ul><ul><ul><li>DateFormat formatter = DateFormat. getDateTimeInstance(DateFormat.FULL, </li></ul></ul></ul><ul><ul><ul><li>DateFormat. FULL, myLocale); </li></ul></ul></ul><ul><ul><ul><li>System. out.println(&quot;Locale is: &quot; + myLocale.getLanguage()); </li></ul></ul></ul><ul><ul><ul><li>System. out.println(formatter.format(myCal.getTime())); </li></ul></ul></ul><ul><li>} </li></ul><ul><li>} </li></ul>
  21. 21. i18n: Content <ul><li>Number Formatter Example </li></ul><ul><li>import java.text.NumberFormat; </li></ul><ul><li>import java.util.Locale; </li></ul><ul><li>public class NumberFormatExample { </li></ul><ul><li>public static void main(String[] args) { </li></ul><ul><ul><ul><li>Locale myLocale = new Locale(args[0]); </li></ul></ul></ul><ul><ul><ul><li>NumberFormat formatter = NumberFormat. getNumberInstance(myLocale); </li></ul></ul></ul><ul><ul><ul><li>System. out.println(&quot;Locale: &quot; + myLocale.toString()); </li></ul></ul></ul><ul><ul><ul><li>System. out.println(formatter.format(123456)); </li></ul></ul></ul><ul><ul><ul><li>System. out.println(formatter.format(123456.78)); </li></ul></ul></ul><ul><li>} </li></ul><ul><li>} </li></ul>
  22. 22. i18n: Resource Bundles <ul><li>Can either be a Java Class or a Property File </li></ul><ul><li>Naming Conventions </li></ul><ul><ul><li>BaseName + locale </li></ul></ul><ul><ul><ul><li>BaseName_language_COUNTRY_Variant </li></ul></ul></ul><ul><ul><ul><li>BaseName_language_COUNTRY </li></ul></ul></ul><ul><ul><ul><li>BaseName_language </li></ul></ul></ul>
  23. 23. i18n: Resource Bundles <ul><li>Three Different Types of Resource Bundles </li></ul><ul><ul><li>Class that extends java.util.ResouceBundle </li></ul></ul><ul><ul><ul><li>Must override getKeys() and handleGetObject() methods or be declared as abstract </li></ul></ul></ul><ul><ul><ul><li>Used when text needs to come from data source other than a text file (i.e. database, webservice, etc.) </li></ul></ul></ul><ul><ul><li>Property Resource Bundles </li></ul></ul><ul><ul><ul><li>Typical implementation – </li></ul></ul></ul><ul><ul><ul><li>No need to override ResourceBundle, just create a property file with the same naming pattern as above, but ends with the “.properties” extension. </li></ul></ul></ul><ul><ul><li>ListResourceBundle </li></ul></ul><ul><ul><ul><li>Can return any type of object </li></ul></ul></ul><ul><ul><ul><li>Often used for localized images </li></ul></ul></ul>
  24. 24. i18n: Resource Bundles – Class Example import java.util.Enumeration; import java.util.Locale; import java.util.ResourceBundle; import java.util.StringTokenizer; public abstract class ResourceBundleExample extends ResourceBundle { private StringTokenizer st = new StringTokenizer(&quot;username password&quot;); @Override public Enumeration getKeys() { return st; } }
  25. 25. i18n: Resource Bundles – Class Example <ul><li>public class ResourceBundleExample_en extends ResourceBundleExample { </li></ul><ul><li>@Override </li></ul><ul><li>protected Object handleGetObject(String key) { </li></ul><ul><ul><ul><li>String msg = null; </li></ul></ul></ul><ul><ul><ul><li>if (&quot;username&quot;.equals(key)) { </li></ul></ul></ul><ul><ul><ul><li>msg = &quot;Username&quot;; </li></ul></ul></ul><ul><ul><ul><ul><li>} else if (&quot;password&quot;.equals(key)) { </li></ul></ul></ul></ul><ul><ul><ul><ul><li>msg = &quot;Password&quot;; </li></ul></ul></ul></ul><ul><ul><ul><ul><li>} else if (&quot;submit&quot;.equals(key)) { </li></ul></ul></ul></ul><ul><ul><ul><ul><li>msg = &quot;Submit&quot;; </li></ul></ul></ul></ul><ul><ul><li>} </li></ul></ul><ul><ul><ul><li>return msg; </li></ul></ul></ul><ul><li>} </li></ul><ul><li>} </li></ul>
  26. 26. i18n: Resource Bundles – Class Example <ul><li>public class ResourceBundleExample_fr extends ResourceBundleExample { </li></ul><ul><li>@Override </li></ul><ul><li>protected Object handleGetObject(String key) { </li></ul><ul><li>String msg = null; </li></ul><ul><li>if (&quot;username&quot;.equals(key)) { </li></ul><ul><ul><li>msg = &quot;Nom d'utilisateur&quot;; </li></ul></ul><ul><li>} else if (&quot;password&quot;.equals(key)) { </li></ul><ul><li>msg = &quot;Mot de passe&quot;; </li></ul><ul><li>} </li></ul><ul><li>return msg; </li></ul><ul><li>} </li></ul><ul><li>} </li></ul>
  27. 27. i18n: Resource Bundles – Class Example <ul><li>import java.util.Locale; </li></ul><ul><li>import java.util.ResourceBundle; </li></ul><ul><li>public class ResourceBundleTester { </li></ul><ul><li>public static void main(String[] args) { </li></ul><ul><ul><ul><li>Locale locale = new Locale(args[0]); </li></ul></ul></ul><ul><ul><ul><li>ResourceBundle bundle = ResourceBundle. getBundle( </li></ul></ul></ul><ul><ul><ul><li>&quot;ResourceBundleExample&quot;, locale); </li></ul></ul></ul><ul><ul><ul><li>System. out.println(&quot;Locale: &quot; + locale.getLanguage()); </li></ul></ul></ul><ul><ul><ul><li>System. out.println(bundle.getString(&quot;username&quot;)); </li></ul></ul></ul><ul><ul><ul><li>System. out.println(bundle.getString(&quot;password&quot;)) </li></ul></ul></ul><ul><ul><li>} </li></ul></ul><ul><li>} </li></ul>
  28. 28. i18n: Resource Bundles – Property File Example # PropertyFileExample_en.properties username= Username (prop file) password= Password (prop file) # PropertyFileExample_fr.properties username= Nom d'utilisateur (prop file) password= Mot de passe (prop file)
  29. 29. i18n: Resource Bundles – Property File Example <ul><li>import java.util.Locale; </li></ul><ul><li>import java.util.ResourceBundle; </li></ul><ul><li>public class PropertyFileTester { </li></ul><ul><li>public static void main(String[] args) { </li></ul><ul><ul><ul><li>Locale locale = new Locale(args[0]); </li></ul></ul></ul><ul><ul><ul><li>ResourceBundle bundle = ResourceBundle. getBundle( </li></ul></ul></ul><ul><ul><ul><li>&quot;PropertyFileExample&quot;, locale); </li></ul></ul></ul><ul><ul><ul><li>System. out.println(&quot;Locale: &quot; + locale.getLanguage()); </li></ul></ul></ul><ul><ul><ul><li>System. out.println(bundle.getString(&quot;username&quot;)); </li></ul></ul></ul><ul><ul><ul><li>System. out.println(bundle.getString(&quot;password&quot;)); </li></ul></ul></ul><ul><li>} </li></ul><ul><li>} </li></ul>
  30. 30. i18n: Resource Bundles – Parameter Example # PropertyFileExample_en.properties username= Username : {0} - {1,date,long} password= Password : {0} - {1,date,long} # PropertyFileExample_fr.properties username= {0} (Nom d''utilisateur) - {1,date,long} password= {0} (Mot de passe) - {1,date,long}
  31. 31. i18n: Resource Bundles – Parameter Example MessageFormat parameters Time or Date : short, medium, long, full, pattern Number: integer, currency, percent, pattern Date Examples Short = 7.9.98 Medium = Jul 9, 1998 Long = July 9, 1998 Full = July 9, 1998 AD
  32. 32. i18n: Resource Bundles – Parameter Example <ul><li>import java.text.MessageFormat; </li></ul><ul><li>import java.util.*; </li></ul><ul><li>public class MessageParameterExample { </li></ul><ul><li>public static void main(String[] args) { </li></ul><ul><ul><ul><li>Locale locale = new Locale(args[0]); </li></ul></ul></ul><ul><ul><ul><li>ResourceBundle bundle = ResourceBundle. getBundle( </li></ul></ul></ul><ul><ul><ul><li>&quot;MessageParameterExample&quot;, locale); </li></ul></ul></ul><ul><ul><ul><li>System. out.println(&quot;Locale: &quot; + locale.getLanguage()); </li></ul></ul></ul><ul><ul><ul><li>Object[] params = { &quot;jason&quot;, new Date() }; </li></ul></ul></ul><ul><ul><ul><li>MessageFormat formatter = new MessageFormat(&quot;&quot;); </li></ul></ul></ul><ul><ul><ul><li>formatter.setLocale(locale); </li></ul></ul></ul><ul><ul><ul><li>formatter.applyPattern(bundle.getString(&quot;username&quot;)); </li></ul></ul></ul><ul><ul><ul><li>System. out.println(formatter.format(params)); </li></ul></ul></ul><ul><ul><ul><li>params = new Object[] { &quot;mypass&quot;, new Date() }; </li></ul></ul></ul><ul><ul><ul><li>formatter = new MessageFormat(&quot;&quot;); </li></ul></ul></ul><ul><ul><ul><li>formatter.setLocale(locale); </li></ul></ul></ul><ul><ul><ul><li>formatter.applyPattern(bundle.getString(&quot;password&quot;)); </li></ul></ul></ul><ul><ul><ul><li>System. out.println(formatter.format(params)); </li></ul></ul></ul><ul><li>} </li></ul><ul><li>} </li></ul>
  33. 33. i18n: Resource Bundles – ListResourceBundle <ul><li>public class ListResourceBundleExample_en_US extends ListResourceBundle { </li></ul><ul><li>static final Object[][] contents = { </li></ul><ul><li>{ &quot;countryFlag&quot;, Toolkit. getDefaultToolkit().getImage(&quot;USflag.jpg&quot;) }, </li></ul><ul><li>{ &quot;countryMap&quot;, Toolkit. getDefaultToolkit().getImage(&quot;USmap.jpg&quot;) } }; </li></ul><ul><li>public Object[][] getContents() { </li></ul><ul><ul><ul><li>return contents; </li></ul></ul></ul><ul><li>} </li></ul><ul><li>} </li></ul>public class ListResourceBundleExample_fr_FR extends ListResourceBundle { static final Object[][] contents = { { &quot;countryFlag&quot;, Toolkit. getDefaultToolkit().getImage(&quot;FRflag.jpg&quot;) }, { &quot;countryMap&quot;, Toolkit. getDefaultToolkit().getImage(&quot;FRmap.jpg&quot;) } }; public Object[][] getContents() { return contents; } }
  34. 34. i18n: Resource Bundles – ListResourceBundle <ul><li>public class ListResourceBundleTester extends JPanel { </li></ul><ul><li>public void paintComponent(Graphics g) { </li></ul><ul><ul><ul><li>g.drawImage(flag, 20, 20, this); </li></ul></ul></ul><ul><ul><ul><li>g.drawImage(map, 20, 20, this); </li></ul></ul></ul><ul><li>} </li></ul><ul><li>public static void main(String arg[]) { </li></ul><ul><ul><ul><li>Locale myLocale = new Locale(arg[0]); </li></ul></ul></ul><ul><ul><ul><li>ListResourceBundle bundle = (ListResourceBundle) ResourceBundle </li></ul></ul></ul><ul><ul><ul><li>. getBundle(&quot;ListResourceBundleExample&quot;, myLocale); </li></ul></ul></ul><ul><ul><ul><li>ListResourceBundleTester tester = new ListResourceBundleTester(); </li></ul></ul></ul><ul><ul><ul><li>tester.setFlag((Image) bundle.getObject(&quot;countryFlag&quot;)); </li></ul></ul></ul><ul><ul><ul><li>tester.setMap((Image) bundle.getObject(&quot;countryMap&quot;)); </li></ul></ul></ul><ul><ul><ul><li>JFrame frame = new JFrame(&quot;List Resource Bundle Tester&quot;); </li></ul></ul></ul><ul><ul><ul><li>frame.setSize(400, 350); </li></ul></ul></ul><ul><ul><ul><li>frame.setDefaultCloseOperation(JFrame. EXIT_ON_CLOSE); </li></ul></ul></ul><ul><ul><ul><li>frame.setContentPane(tester); </li></ul></ul></ul><ul><ul><ul><li>frame.setVisible(true); </li></ul></ul></ul><ul><li>} </li></ul><ul><li>// ... </li></ul>
  35. 35. i18n: Resource Bundles <ul><li>How is a resource bundle selected? </li></ul><ul><li>The submitted locale is inspected and a resource bundle with that specific locale is searched for. </li></ul><ul><li>If one isn’t found it tries to find one with less specific details </li></ul><ul><ul><li>If the locale contains a variant, the variant is dropped </li></ul></ul><ul><ul><ul><li>(i.e. BaseName_language_COUNTRY) </li></ul></ul></ul><ul><ul><li>If nothing is found, and the locale contains a country, the country is dropped </li></ul></ul><ul><ul><ul><li>(i.e. BaseName_language) </li></ul></ul></ul><ul><li>If nothing is found it looks at the “default” locale of the system. </li></ul>
  36. 36. i18n: Resource Bundles <ul><li>Like the original submitted locale, it first tries to find a resource bundle that matches the exact locale. </li></ul><ul><li>If nothing is found, it starts to remove specific locale information: </li></ul><ul><ul><li>If the default Locale contains a variant, the variant is dropped </li></ul></ul><ul><ul><ul><li>(i.e. BaseName_language_COUNTRY) </li></ul></ul></ul><ul><ul><li>If nothing is found, and the Locale contains a country, the country is dropped </li></ul></ul><ul><ul><ul><li>(i.e. BaseName_language) </li></ul></ul></ul><ul><li>Finally, if nothing is found, it tries to find a default bundle with the “base name” and nothing more. </li></ul>
  37. 37. i18n: Resource Bundles <ul><li>If nothing is found, a “MissingResource” exception is thrown. </li></ul><ul><li>Once a resource bundle is located, there is an attempt to find the key being requested. </li></ul><ul><li>If the key isn’t found in the selected bundle, less specific bundles will be inspected to find the key. </li></ul><ul><ul><li>If the selected bundle contains a variant, the variant is dropped </li></ul></ul><ul><ul><li>If the keys is not found, the selected bundle contains a country, the country is dropped </li></ul></ul><ul><ul><li>If the key is not found, the language is dropped and a default bundle is searched </li></ul></ul>
  38. 38. i18n: Resource Bundles Quiz <ul><li>ResourceBundleQuiz.properties </li></ul><ul><li>username=jason (base) </li></ul><ul><li>password=mypass (base) </li></ul><ul><li>ResourceBundleQuiz_en.properties </li></ul><ul><li>username=jason (en) </li></ul><ul><li>ResourceBundleQuiz_en_US.properties </li></ul><ul><li>password=jason (en_US) </li></ul><ul><li>state=minnesota (en_US) </li></ul><ul><li>ResourceBundleQuiz_fr.properties </li></ul><ul><li>username=jason (fr) </li></ul>#1 - My Locale: fr Default Locale: en Key: password
  39. 39. i18n: Resource Bundles Quiz <ul><li>ResourceBundleQuiz.properties </li></ul><ul><li>username=jason (base) </li></ul><ul><li>password=mypass (base) </li></ul><ul><li>ResourceBundleQuiz_en.properties </li></ul><ul><li>username=jason (en) </li></ul><ul><li>ResourceBundleQuiz_en_US.properties </li></ul><ul><li>password=jason (en_US) </li></ul><ul><li>state=minnesota (en_US) </li></ul><ul><li>ResourceBundleQuiz_fr.properties </li></ul><ul><li>username=jason (fr) </li></ul>#2 - My Locale: en Default Locale: fr Key: password
  40. 40. i18n: Resource Bundles Quiz <ul><li>ResourceBundleQuiz.properties </li></ul><ul><li>username=jason (base) </li></ul><ul><li>password=mypass (base) </li></ul><ul><li>ResourceBundleQuiz_en.properties </li></ul><ul><li>username=jason (en) </li></ul><ul><li>ResourceBundleQuiz_en_US.properties </li></ul><ul><li>password=jason (en_US) </li></ul><ul><li>state=minnesota (en_US) </li></ul><ul><li>ResourceBundleQuiz_fr.properties </li></ul><ul><li>username=jason (fr) </li></ul>#3 - My Locale: ja Default Locale: fr_CA Key: username
  41. 41. i18n: Resource Bundles Quiz <ul><li>ResourceBundleQuiz.properties </li></ul><ul><li>username=jason (base) </li></ul><ul><li>password=mypass (base) </li></ul><ul><li>ResourceBundleQuiz_en.properties </li></ul><ul><li>username=jason (en) </li></ul><ul><li>ResourceBundleQuiz_en_US.properties </li></ul><ul><li>password=jason (en_US) </li></ul><ul><li>state=minnesota (en_US) </li></ul><ul><li>ResourceBundleQuiz_fr.properties </li></ul><ul><li>username=jason (fr) </li></ul>#4 - My Locale: fr_CA Default Locale: en_US Key: username
  42. 42. i18n: Resource Bundles Quiz <ul><li>ResourceBundleQuiz.properties </li></ul><ul><li>username=jason (base) </li></ul><ul><li>password=mypass (base) </li></ul><ul><li>ResourceBundleQuiz_en.properties </li></ul><ul><li>username=jason (en) </li></ul><ul><li>ResourceBundleQuiz_en_US.properties </li></ul><ul><li>password=jason (en_US) </li></ul><ul><li>state=minnesota (en_US) </li></ul><ul><li>ResourceBundleQuiz_fr.properties </li></ul><ul><li>username=jason (fr) </li></ul>#5 - My Locale: en Default Locale: fr Key: state
  43. 43. i18n: Collation <ul><li>Different Regional / Language Rules </li></ul><ul><li>Multi-Character Contractions </li></ul><ul><li>Single Character Extractions </li></ul><ul><li>Using a Collator </li></ul><ul><li>Collator strength </li></ul><ul><ul><li>Four types from least restrictive to most restrictive: Primary , Secondary , Tertiary , and Identical </li></ul></ul><ul><ul><li>Collator default strength is set to Tertiary </li></ul></ul><ul><ul><li>Their specific meaning is Locale dependent </li></ul></ul>
  44. 44. i18n: Collation Collator collate = Collator.getInstance( myLocale ); collate.setStrength(Collator.IDENTICAL); Collections.sort( customerList, collate );
  45. 45. i18n: GUI Considerations <ul><li>Layout </li></ul><ul><ul><li>Different regions expect information to flow in different directions </li></ul></ul><ul><ul><li>Hebrew, for example, is written right to left </li></ul></ul><ul><ul><li>Items may be reversed or in a different order to satisfy the expectations of a given region. </li></ul></ul><ul><ul><li>Menu items may need to flow in different directions as well. </li></ul></ul><ul><li>Localized Images </li></ul><ul><ul><li>Containing Text </li></ul></ul><ul><ul><ul><li>Will need to be swapped out with images that contain text for each supported region </li></ul></ul></ul><ul><ul><li>Regional context </li></ul></ul><ul><ul><ul><li>Some images and colors have specific meanings in different regions. Ignoring these issues can cause confusion, or possibly be insulting </li></ul></ul></ul>
  46. 46. i18n: GUI Considerations <ul><li>Character Expansion / Contraction </li></ul><ul><ul><li>Different languages may push out GUI elements by having longer translations </li></ul></ul><ul><ul><li>Character direction may also impact the layout of GUI elements. </li></ul></ul>
  47. 47. i18n: Character Sets & Encoding <ul><li>Code Sets </li></ul><ul><ul><li>Each unique code represents a unique character </li></ul></ul><ul><ul><li>ASCII </li></ul></ul><ul><ul><ul><li>7 Bit, 128 Characters </li></ul></ul></ul><ul><ul><li>ISO-8859-1 </li></ul></ul><ul><ul><ul><li>8 Bit, 256 Characters, “Latin 1” </li></ul></ul></ul><ul><ul><li>Unicode </li></ul></ul><ul><ul><ul><li>16 Bit, as of version 2.0, contains 1,114,112 code points </li></ul></ul></ul>
  48. 48. i18n: Character Sets & Encoding <ul><li>Encoding </li></ul><ul><ul><li>Modal </li></ul></ul><ul><ul><ul><li>Escape characters </li></ul></ul></ul><ul><ul><li>Nonmodal </li></ul></ul><ul><ul><ul><li>Number of bytes per character is determined by what range they fall into. </li></ul></ul></ul><ul><ul><li>UTF-8 </li></ul></ul><ul><ul><li>Encoding Must Be Set in Servlets and JSPs </li></ul></ul>
  49. 49. i18n: Character Sets & Encoding <ul><li>Setting Encoding in Servlets </li></ul><ul><ul><li>response.setCharacterEncoding(&quot;UTF-8&quot;); </li></ul></ul><ul><ul><li>or combine it with the Content Type: </li></ul></ul><ul><ul><li>response.setContentType(&quot;text/html; charset=utf-8&quot;); </li></ul></ul><ul><li>Settings Encoding in JSPs </li></ul><ul><ul><li><%@page pageEncoding=&quot;UTF-8&quot;%> </li></ul></ul><ul><li>Page Encoding in Property Files </li></ul><ul><li>native2ascii </li></ul>
  50. 50. i18n: Third Party Tools <ul><li>IBM’s ICU4J </li></ul><ul><ul><li>http://site.icu-project.org/ </li></ul></ul><ul><li>JSTL Example </li></ul><%@ page contentType=&quot;text/html; charset=UTF-8&quot; %> <%@ taglib uri=“http://java.sun.com/jsp/jstl/fmt” prefix=“fmt” %> <fmt:setBundle basename=“MyMessages&quot; var=“bundle&quot; scope=&quot;session&quot;/> <fmt:setLocale value=“${user.locale}” scope=“session” /> <fmt:message key=“greeting” bundle=“${bundle}”/>
  51. 51. i18n: Third Party Tools <ul><li>JSF Example </li></ul>// FacesConfig.xml <application> <locale-config> <default-locale>en_US</default-locale> <supported-locale>ja</supported-locale> <supported-locale>fr</supported-locale> </locale-config> <message-bundle>com.intertech.MyMessages</message-bundle> </application> // JSF View <%@taglib uri=“http://java.sun.com/jsf/html” prefix=“h” %> <%@taglib uri=“http://java.sun.com/jsf/core” prefix=“f” %> <f:loadBundle basename=“com.intertech.MyMessages var=“txt” /> <h:outputText value=“#{txt.username}” />
  52. 52. Localization (l10n) <ul><li>Submitting Resource Bundles </li></ul><ul><ul><li>Screenshots w/ functional descriptions </li></ul></ul><ul><li>Words vs. Context </li></ul><ul><li>Localized Testing </li></ul><ul><ul><li>Correctness is grammar / context </li></ul></ul><ul><ul><li>GUI displacement </li></ul></ul><ul><ul><li>Cultural considerations </li></ul></ul>
  53. 53. i18n / l10n Resources <ul><li>Deitsch, Andrew, and David Czarnecki. Java Internationalization . Sebastopol: O'Reilly, 2001. </li></ul><ul><li>Esselink, Bert. A Practical Guide to Localization . Philadelphia: John Benjamins, 2000. </li></ul><ul><li>Gillam, Richard. Unicode Demystified . Boston: Addison-Wesley, 2003. </li></ul><ul><li>&quot;ICU - International Components for Unicode&quot;. 9/9/2009 <http://site.icu-project.org/>. </li></ul><ul><li>&quot;Internationalization (i18n) Forum&quot;. Sun Microsystems. 9/9/2009 <http://forums.sun.com/forum.jspa?forumID=16>. </li></ul><ul><li>Savourel, Yves. XML Internationalization and Localization . Indianapolis: Sams, 2001. </li></ul>
  54. 54. Related Courses at Intertech <ul><li>Complete Java </li></ul><ul><ul><li>http://www.intertech.com/Courses/Course.aspx?CourseID=99098 </li></ul></ul><ul><li>Complete Java Web Development </li></ul><ul><ul><li>http://www.intertech.com/Courses/Course.aspx?CourseID=99076 </li></ul></ul><ul><li>Complete Spring Framework </li></ul><ul><ul><li>http://www.intertech.com/Courses/Course.aspx?CourseID=99367 </li></ul></ul><ul><li>Complete JSF </li></ul><ul><ul><li>http://www.intertech.com/Courses/Course.aspx?CourseID=99339 </li></ul></ul><ul><li>Complete Struts </li></ul><ul><ul><li>http://www.intertech.com/Courses/Course.aspx?CourseID=99251 </li></ul></ul>
  55. 55. Intertech Resources <ul><li>Facebook </li></ul><ul><ul><li>http://facebook.intertech.com </li></ul></ul><ul><li>Twitter </li></ul><ul><ul><li>http://twitter.intertech.com </li></ul></ul><ul><li>LinkedIn </li></ul><ul><ul><li>http://linkedin.intertech.com </li></ul></ul><ul><li>YouTube </li></ul><ul><ul><li>http://youtube.intertech.com </li></ul></ul><ul><li>Decoupled Musings (Jason Shapiro) </li></ul><ul><ul><li>http://decoupledmusings.blogspot.com </li></ul></ul><ul><li>White’s Board (Jim White) </li></ul><ul><ul><li>http://whitesboard.blogspot.com/ </li></ul></ul>
  56. 56. What you have learned today <ul><li>Globalization: Definition & Terms </li></ul><ul><li>Project Stages </li></ul><ul><ul><li>Internationalization </li></ul></ul><ul><ul><li>Localization </li></ul></ul><ul><ul><li>Testing </li></ul></ul><ul><li>Internationalization </li></ul><ul><ul><li>Locales </li></ul></ul><ul><ul><li>Content </li></ul></ul><ul><ul><li>Resource Bundles </li></ul></ul><ul><ul><li>Collation </li></ul></ul><ul><ul><li>GUI Considerations </li></ul></ul>
  57. 57. What you have learned today <ul><li>Internationalization (continued) </li></ul><ul><ul><li>Character Encoding </li></ul></ul><ul><ul><li>3 rd Party Tools </li></ul></ul><ul><li>Localization </li></ul><ul><ul><li>Submitting Resource Bundles </li></ul></ul><ul><ul><li>Words vs. Context </li></ul></ul><ul><ul><li>Testing </li></ul></ul>
  58. 58. Intertech Resources <ul><li>Intertech offers free: </li></ul><ul><ul><li>Content packed newsletters </li></ul></ul><ul><ul><li>Podcasts through iTunes </li></ul></ul><ul><ul><li>YouTube videos </li></ul></ul><ul><ul><li>Free Oxygen Blast seminars </li></ul></ul><ul><ul><li>Whitepapers and .pdf downloads </li></ul></ul><ul><li>For the above and special offers, register for the newsletter at the bottom of our homepage </li></ul>
  59. 59. Intertech Training <ul><li>Founded in 1991, Intertech offers a full training line-up: </li></ul><ul><ul><li>JEE, open source technologies </li></ul></ul><ul><ul><li>.NET, SQL Server, SharePoint </li></ul></ul><ul><ul><li>XML, Ajax </li></ul></ul><ul><li>Delivery formats include: </li></ul><ul><ul><li>Instructor-led public and onsite </li></ul></ul><ul><ul><li>Instructor-led night and virtual </li></ul></ul><ul><ul><li>Self-paced study </li></ul></ul><ul><ul><li>For advanced purchase customers, Intertech offers Elite Rewards™—call 651-994-8558 +23 </li></ul></ul>
  60. 60. Intertech Consulting <ul><li>In addition to training, Intertech delivers consulting </li></ul><ul><li>Consulting is part of our brand: Instructors Who Consult | Consultants Who Teach </li></ul><ul><li>Give your project success with our consulting services </li></ul><ul><li>To learn more, contact us at 651-994-8558 +11 </li></ul>
  61. 61. Thank You! http://www.intertech.com

×