Globalizing Your Java Application Training

Loading...

Flash Player 9 (or above) is needed to view presentations.
We have detected that you do not have it on your computer. To install it, go here.

0 comments

Post a comment

    Post a comment
    Embed Video
    Edit your comment Cancel

    1 Favorite

    Globalizing Your Java Application Training - Presentation Transcript

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

    + Intertech TrainingIntertech Training, 2 months ago

    custom

    134 views, 1 favs, 0 embeds more stats

    Globalization: Definition & Terms

    Project Stages more

    More info about this document

    © All Rights Reserved

    Go to text version

    • Total Views 134
      • 134 on SlideShare
      • 0 from embeds
    • Comments 0
    • Favorites 1
    • Downloads 0
    Most viewed embeds

    more

    All embeds

    less

    Flagged as inappropriate Flag as inappropriate
    Flag as inappropriate

    Select your reason for flagging this presentation as inappropriate. If needed, use the feedback form to let us know more details.

    Cancel
    File a copyright complaint
    Having problems? Go to our helpdesk?

    Categories