• Save
Globalizing Your Java Application Training
Upcoming SlideShare
Loading in...5
×
 

Globalizing Your Java Application Training

on

  • 2,183 views

Globalization: Definition & Terms ...

Globalization: Definition & Terms

Project Stages
Internationalization
Localization
Testing

Internationalization
Locales
Content
Resource Bundles
Collation
GUI Considerations

Statistics

Views

Total Views
2,183
Views on SlideShare
2,179
Embed Views
4

Actions

Likes
1
Downloads
0
Comments
0

1 Embed 4

http://www.slideshare.net 4

Accessibility

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Globalizing Your Java Application Training Globalizing Your Java Application Training Presentation Transcript

    • Globalizing Your Java Application Intertech’s Oxygen Blast Series September 2009
    • 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”
    • Agenda
      • Globalization: Definition & Terms
      • Project Stages
        • Internationalization
        • Localization
        • Testing
      • Internationalization
        • Locales
        • Content
        • Resource Bundles
        • Collation
        • GUI Considerations
    • Agenda
      • Internationalization (continued)
        • Character Encoding
        • 3 rd Party Tools
      • Localization
        • Submitting Resource Bundles
        • Words vs. Context
        • Testing
      • Questions / Open Discussion
    • Available On Line
      • Slides
        • http://www.intertech.com/downloads/o2-i18n.pptx
    • 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.”
    • 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.
    • Project Stages
      • Internationalization
      • Create documentation for translation services
      • Localization Testing
    • 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.
    • 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
    • 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
    • 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
    • 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)
    • 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 );
    • 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
    • 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.
    • 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
    • i18n: Content
      • Numbers / Currency
        • Characters
        • Groupings and Delimiters
          • 481,516.23 vs. 481.516,23 vs. 481 516,23
        • Symbols
      • Images
    • 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
    • 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()));
      • }
      • }
    • 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));
      • }
      • }
    • 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
    • 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
    • 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; } }
    • 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;
      • }
      • }
    • 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;
      • }
      • }
    • 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"))
        • }
      • }
    • 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)
    • 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"));
      • }
      • }
    • 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}
    • 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
    • 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));
      • }
      • }
    • 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; } }
    • 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);
      • }
      • // ...
    • 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.
    • 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.
    • 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
    • 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
    • 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
    • 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
    • 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
    • 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
    • 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
    • i18n: Collation Collator collate = Collator.getInstance( myLocale ); collate.setStrength(Collator.IDENTICAL); Collections.sort( customerList, collate );
    • 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
    • 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.
    • 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
    • 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
    • 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
    • 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}”/>
    • 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}” />
    • Localization (l10n)
      • Submitting Resource Bundles
        • Screenshots w/ functional descriptions
      • Words vs. Context
      • Localized Testing
        • Correctness is grammar / context
        • GUI displacement
        • Cultural considerations
    • 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.
    • 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
    • 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/
    • What you have learned today
      • Globalization: Definition & Terms
      • Project Stages
        • Internationalization
        • Localization
        • Testing
      • Internationalization
        • Locales
        • Content
        • Resource Bundles
        • Collation
        • GUI Considerations
    • What you have learned today
      • Internationalization (continued)
        • Character Encoding
        • 3 rd Party Tools
      • Localization
        • Submitting Resource Bundles
        • Words vs. Context
        • Testing
    • 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
    • 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
    • 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
    • Thank You! http://www.intertech.com