The document discusses internationalizing Java, JavaFX, AJAX, and portlet applications. It begins with an overview of globalization, internationalization, localization, and translation. It then covers:
1) Internationalization support in Java, including resource bundles and locale handling.
2) Internationalization of AJAX applications, including setting encodings on the server and client sides.
3) Internationalization of portlet applications, including setting encodings and using resource bundles.
4) Internationalization of JavaFX applications, including setting the default locale, using resource bundles, and formatting dates for different locales.
The document concludes with exercises to internationalize applications of each technology.
Internationalize Java, JavaFX, AJAX and Portlet Applications
1. Learn to Internationalize your
Java, JavaFX, AJAX and Portlet
Applications
Shankar Gowda & Shrinath Hedge
Globalization Engineering
Sun Microsystems, Inc.
2. Agenda
Globalization Overview
>
What's with acronyms and definitions ?
>
How do they differ and relate ?
>
Introducing Internationalization(i18n) in various technologies
>
Language Exercises (100 mins)
>
– Exercise 0: Setup Lab Environments
– Exercise 1: Internationalize your Java application
– Exercise 3: Internationalize AJAX Web application
– Exercise 4: Internationalize Portlet application
– Exercise 2: Internationalize JavaFX application
> Tools, Summary and References
2
3. Globalization acronyms
Globalization [G1 1 n]
“Globalization addresses the business issues associated with taking a
product global. In the globalization of high-tech products this involves
integrating localization throughout a company, after proper
internationalization and product design, as well as marketing, sales, and
support in the world market.”
Internationalization [i1 8n]
“Internationalization is the process of generalizing a product so that it can
handle multiple languages and cultural conventions without the need for
re-design. Internationalization takes place at the level of program design
and document development.”
Localization [L1 0n]
“Localization involves taking a product and making it linguistically and
culturally appropriate to the target locale (
country/
region and language)
where it will be used and sold.”
Translation ===> T9n
3
4. How do they differ and relate ?
• Globalization at the architecture level
• Internationalization ( 8n)enables Localization
i1
• An expert in i1 8n may not be an expert in l1 0n
• I18n (code) + l10n(linguistic) + T9n (translation)
= G11n (process)
4
5. Internationalization support in Java
Java Platform is Internationalized
➢
Extensive library of classes and functions
●
I18n support comes for free or at very little cost
●
Built-in I18n support for over 70 languages
●
All text in a running Java program is Unicode
➢
5
7. Example Code: Before Internationalization
System.out.println(“Hello”);
System.out.println(“Sun Tech Days”);
System.out.println(“Hyderabad”);
7
8. Example Code: After Internationalization
Locale myLocale = new Locale(myLanguage, myCountry);
ResourceBundle messages =
ResourceBundle.getBundle(“messageBundle, myLocale);
System.out.println(messages.getString(“greeting”));
System.out.println(messages.getString(“event”));
System.out.println(messages.getString(“place”));
Your Resource Bundle property catalog file will have,
greeting=Hello
event=Sun Tech Days
place=Hyderabad
8
9. Introduction to AJAX
> AJAX = acronym for
Asynchronous JavaScript and XML
– Browser client uses JavaScript to Asynchronously
– get XML data from a server and update page
– dynamically without refreshing the whole page
> Why is AJAX so popular ?
– Increase Usability of Web Application
– Save Bandwidth
– Download only data you need
– End user Sequence and Faster interfaces
> Side effects of AJAX ?
– Breaks back button support
– URL's don't change as state changes
– Cross Browser Issues can be a pain
9
11. Traditional Web AJAX
within a browser,
there is AJAX engine
11
12. AJAX Internationalization
• Server Side: By setting the appropriate Request
and Response Object to a right encoding in
Servlet controller
> In doGet method
– request.setCharacterEncoding(“UTF-8”);
> In sendResonse method
– response.setContentType(“text/xml;
charset=utf-8”);
> Using Resource Bundle for externalizing messages to
property files and naming them to appropriate locale
variant.
• Client Side: By setting your browser to UTF-8
encoding.
12
13. Introducing Portlet Application
> Specialized Web application that
provides value-added services like,
– Personalization, Single Sign-On,
Content Aggregation, Dynamic
Drag and Drop, Work From
Desktop, Search& Tagging.
> Portlet is a piece of markup called
as 'Fragment'
> A Portal Application can have
multiple portlets.
– Window functionalities like,
minimize, maximize, configure,
close..etc
> Portal Administration for Role, Look
& Feel, Permissions, SOA, JAI
> Includes Wikis, Message Boards,
Blogs, Email, IM, Activity Tracking,
Calendar, etc.. 13
15. Internationalizing your Portlet
> Server Side: By setting the appropriate Resquest and
Response Objects to right encoding in Servlet/JSP
controller.
– Adding locale support in your portlet.xml
<supported-locale>hi</supported-locale>
– JSP Page Directive
<%page contentType=”text/html; charset=UTF-8”%>
<%page pageEncoding=”UTF-8” %>
– Using JSTL FMT library
<% taglib uri=”http://java.sun.com/jsp/jstl/fmt”
prefix=”fmt” %>
– Setting Resource Bundle
<fmt.setBundle basename=”PackageName.BundleName” />
– Calling the tag lib in your JSP page
<fmt:message key=”name”/>
> Client Side: Set your browser encoding to UTF-8.
15
16. Let us start the LAB with Exercise 0
> Install Java SE 6 update 10 or above
> Install NetBeans 6.5 with GlassFish V2/V3
> Copy i18nHOL.zip and
unzip
– Will create i18nHOL
directory =
<lab_root>
– It contains the following:
– Start with index.html
– Exercises directory like
16
21. JavaFX Overview
JavaFX platform FX
●
JavaFX Desktop
●
● JavaFX Mobile and JavaFX TV
● Other devices and screens to follow
Tools Suite
●
JavaFX Developer (Plug-ins for IDEs, Media
●
converters, RAD tools)
● JavaFX Designer (Authoring, Video
Encoding)
Suite of Applications build on JavaFX
●
● JavaFX Content, Applications & Services
21
23. JavaFX Script Programming Language
Declarative, statically-typed scripting language
>
Facilitates rapid GUI development
>
Many cool, interesting language features
>
Runs on Virtual Machine for the Java™ platform
>
Deployment options same as Java programs
>
Fully utilizes Java class libraries behind the scenes
>
For content designers and Media engineers
>
Supports primitive types like, String, Boolean, Number,
>
Integer, Duration.
> Supports Objects, Multiple Inheritance and any Java
Objects can be used in JavaFX.
23
25. Introducing Internationalization in JavaFX
> Creating a Locale Object
> Setting the default locale
> Create Resource Bundle property file as
“Main_hi_IN.fxproperties”
> Resource bundle messages are called just by
prefixing with '##'
> Reduces complexity! Compared to Java Resource
Bundle
25
26. Internationalizing Dates in JavaFX
> Supports Java printf-style formats
> Uses same Formatter as Java
> POSIX standard strftime spec.
26
27. Internationalizing of Dates in JavaFX
• Formats
– %tx – Locale's appropriate date representation
– %tX – Locale's appropriate time representation
– %tg – The last two digits of the week-based year (ISO 8601)
– %tG – Week-based year (ISO 8601)
– %tu – Day of week ( Monday is 1) [ 1,7 ]
– %tV – ISO 8601 Week number of the Year.
27
28. Looking at locale based sorting for JavaFX
> Create a List of words
> Create the Instance of Collator by specifying the
Locale.
> Define the function for Sorting and displaying the List
of words.
28
29. Locale based Sorting using Collator
> In sort function we will call Collections.sort, that sorts
the list of words in ascending order by giving the
words list and strength of the collator as arguments.
> Append the output to a variable.
> Display as,
29
30. Exercise 2: Learn to i18n JavaFXSphere
• Install, Configure Lab environment
• Creating a FirstJavaFXSphere Application
• Internationalizing the code of FirstJavaFXSphere
application
• Externalizing the messages to
Main_hi_IN.fxproperties
• Localizing in Hindi
30
38. JavaFX: Command Line Development
include <javafx-sdk>/bin in PATH
•
javafxc to compile
•
javafx to run
•
Relevant library files in <javafx-sdk>/lib are
•
automatically included in classpath as necessary.
Rest can be included with the -classpath option
> With packages
● javafxc -d . firstjavafxsphere/Main.fx
● javafx firstjavafxsphere.Main
> Without packages
● javafxc Main.fx
● javafx Main
38