Multilingual Web Applications With JavaJ2EE

1 / 42
About This Presentation
Title:

Multilingual Web Applications With JavaJ2EE

Description:

Multilingual Web Applications With Java/J2EE. Presented by Jason Shepherd ... in planning phase for Canada French and Germany German. Why Internationalization? ... – PowerPoint PPT presentation

Number of Views:62
Avg rating:3.0/5.0
Slides: 43
Provided by: bass1

less

Transcript and Presenter's Notes

Title: Multilingual Web Applications With JavaJ2EE


1
Multilingual Web Applications With Java/J2EE
  • Presented by Jason Shepherd
  • Bass and Associates, Inc., a HunTel Company
  • 12-Oct-2005, 1130 AM
  • ITEC 2005, HyVee Hall, Des Moines, Iowa

2
First, our apologies Our initial presenters,
internationalization experts, and design
leads Napolean Dynamite and Pedro Sanchez are
unable to attend. Theyre off building a cake, or
something. So youre stuck listening to me.
3
Outline
  • Bass and Associates, Inc.
  • Why Internationalization
  • What is Internationalization?
  • Goals
  • Technical Design and Common Issues
  • J2EE
  • XSLT (optional)
  • The Process of Internationalization

4
Bass and Associates
  • Bass consultants lead an Internationalization
    effort of an automotive delivery logistics
    application for one of the Big Three car
    manufacturers
  • Initial implementation offered application in
    both US English and Mexico Spanish
  • Currently in planning phase for Canada French and
    Germany German

5
Why Internationalization?
  • Hard to do business in a global marketplace if
    you cant speak the users language (or
    languages)
  • Good strategy for sales/marketing
  • Broadens spectrum of potential customers

6
But what is Internationalization?
You keep using that word. I do not think it
means what you think it means.
The Princess Bride, 20th Century Fox, 1987
7
What is Internationalization?
  • process of creating an application so it can be
    adapted to different languages and countries
    without coding changes
  • also known as i18n (since there are 18
    characters between the i and n)

8
What is Internationalization?
  • Characteristics of an i18n application
  • By adding localized text, the app can display
    information in any language/country
  • Textual elements are not hard-coded they are
    stored externally and retrieved at run-time

9
What is Internationalization?
  • Characteristics of an i18n application (cont)
  • Support for new languages/countries does not
    require re-compilation
  • Culturally dependent data (dates, currencies,
    etc.) conforms to users language/country
  • Can be localized quickly

10
Localization
  • process of adapting software for a specific
    language/country by adding locale-specific
    components and text translations
  • sometimes abbreviated as l10n (10 letters between
    L and N)

11
Localizing an Application
  • text translation is the most time-consuming phase
    of l10n (the human element)
  • sounds and images may need localized if they are
    culturally sensitive (red indicates danger in
    the US, but in some countries it means purity
    likewise the icon of a mailbox isnt familiar
    outside the U.S., and instead a mail envelope
    icon should be used)
  • formatting of numbers, dates, and currencies
  • may impact the UI layout strategy

12
Locale
  • Users locale is the object central to l10n
  • political, cultural, and region-specific elements
    (for Java-based applications, expressed as a
    language code and country code)

13
Locale (cont)
  • has the form xx_YY
  • xx is 2-character language code (ISO-639)
  • YY is 2-character country code (ISO-3166)
  • Examples
  • en_US - United States English
  • en_GB - Great Britain English
  • es_MX - Mexico Spanish (Espanol)

14
Design Goals
One of my goals is to have sweet tetherball
skills.
15
Design Goals
  • Create framework for rapid adoption of new
    languages/regions
  • framework should have negligible impact on
    performance and resources
  • framework should scale in terms of
  • of locales, of users, content size
  • framework should be easy to maintain
  • translations should be centralized
  • future content/functionality must be i18n

16
Technical Design
Finally the cool stuff. I love technology.
17
Example Web Tier(prior)
HTTP request
ActionServlet
CredentialsFilter
To Service Tier
HTTP response
HTTP response
18
i18n for J2EE Apps
  • Locale stored in HTTP session
  • Resource bundles stored in properties files told
    to load in web.xml
  • Access locale-specific messages in the Web tier
    using tag libraries
  • Struts tag libraries versus JSTL
  • Access locale-specific messages elsewhere using
    custom code
  • Locale-specific messages for XSLT

19
The Locale Object
  • java.util.Locale
  • Locale locale new Locale(en, US)
  • session.setAttribute(org.apache.struts.action.Acti
    on.LOCALE_KEY, locale)

20
Properties Files
  • Plain text file
  • Will reside in classpath
  • One file for each locale (filename convention)
  • When paired with a locale, the closest matching
    file will be selected

MyApp.properties MyApp_en.properties MyApp_en_US.p
roperties MyApp_es_MX.properties
default
21
Properties Files (cont)
  • Creating properties files (cont)

MyApp_en_US.properties
greetings Hello. farewell Goodbye. inquiry
How are you?
MyApp_fr_FR.properties
greetings Bonjour. farewell Au
revoir. inquiry Comment allez-vous?
22
Properties Files (cont)
  • Ensure your properties files are visible on the
    classpath
  • make sure your build process (e.g. Apache Ant) is
    grabbing the properties files and putting them in
    the proper location
  • must be placed somewhere that all classes will be
    able to find it (e.g. a library jar file or
    possibly in the WAR file under WEB-INF/classes)

23
Side Notes
  • Properties files and resource bundle keys should
    follow human-readable naming conventions (not
    key1, key2, etc.)
  • IDEs dont help much here
  • Our convention
  • general.vin, general.railcar
  • vehicleTrace.dealerName
  • netMap.critAlert

24
J2EE (w/ Struts)
  • Configure web.xml to load the properties files

action
org.apache.struts
.action.ActionServlet
applicationme MyApp

locale
true
25
JSP (w/ Struts)
  • Accessing the resource bundles in a JSP
  • First, include the Struts bean tag library
  • prefix"bean"
  • Then, replace any hard-coded messages
  • Hello

26
JSP Side Notes
  • Properties files can be HTML escape encoded
    (aacute) or Unicode encoded (\u0000) Struts
    taglibs are encoding-aware
  • The content type in your resulting HTML page must
    be set correctly (content type tells browser what
    character set youre using)

27
J2EE
  • Accessing outside of a JSP context
  • UI utility classes or custom taglibs
  • We wrote a utility class to load the properties
    files and retrieve messages

Locale locale (Locale) session.getAttribute(org.
apache.struts.action.Action.LOCALE_KEY) String
message ResourceBundleUtil.getMessage( locale,
hello.message) this class comes in handy
when we try to i18n our XSLT stylesheets stay
tuned!
28
Design Issue The Database Temptation
  • JSTL and Struts Taglibs dont support access to
    localized content in a database (would have to
    rewrite Struts or create custom solution)
  • If DB is shared between applications, all
    applications using the DB must be i18n-enabled
  • DB must be Unicode-enabled and have plenty of
    extra disk space

29
Design Issue The Database Temptation
  • Requires more database accesses
  • Very bad for high volume sites where database
    connections must be managed carefully
  • Issue of scale
  • Might require complex joins in a normalized DB
    schema

30
Design Issue Assigning a Users Locale
  • Accepted languages HTTP header (set in browser
    preferences)
  • Little/no control over available languages
  • User still might want to change language
  • Cookie
  • Works with both static and dynamic sites
  • Store locale in DB
  • Retrieve users locale when user first logs in
  • Only works for dynamic site

31
Design Issue Other Information
  • References to other static content must be
    localized too
  • Suggest placing images, JavaScript, etc., in
    separate content directories for each locale
  • Then, use scriptlets or taglibs to access content

/im/header.gif
/
locale /js/errorMessages.js
32
Design Issue UI Layout
  • Widths and heights of screen elements may be
    impacted
  • Railcar Trace
  • Rastreo des Plataformas
  • Need obvious way to change language
  • Language names should be in their native language
  • e.g., Espanol, not Spanish

33
Internationalization in XSLT
  • Some J2EE applications deliver their data to the
    Web tier as XML and then render the UI using XSLT
    (or a combination of JSP and XSLT)
  • We have resource bundles all nice and neat, but
    no way to access them in XSLT

34
XSLT
  • Different approaches to i18n in this case
  • Option 1 Not try to use properties files
    instead, make a separate XSLT stylesheet for each
    locale (yuck! Must be maintained and manually
    synchronized with the properties files)
  • Option 2 Write code to insert the locale into
    the stylesheet as an XSL variable. Then use Java
    from within your stylesheet to extract the
    resource bundle messages (Xalan-Java extensions)

35
XSLT
  • XSLT stylesheets can be localized the same way
    JSPs are.
  • But, XSLT stylesheets don't have access to the
    Java HTTP session object that stores the users
    locale information
  • The locale must be inserted into the XSLT and
    passed to the Xalan-Java objects

36
XSLT An i18n (not l10n yet) Stylesheet
tml" xmlnsxsl"http//www.w3.org/1999/XSL/Trans
form" xmlnsinl"http//www.insightnl.com" xmlns
message"http//xml.apache.org/xalan/java/com.upr
r.app.inl.util.ResourceBundleUtil"
version"0.1" select"messagegetMessage(locale,hello.message
)"/
37
XSLT Retrieving the Stylesheet and Inserting the
Locale
Note we store our XSLT in the DB
38
XSLT Retrieving the Stylesheet and Inserting the
Locale
This XSLT is applied to an i18n XSLT to create a
L10n XSLT. The locale is extracted from the
session and inserted into a StringBuffer using a
Java utility class in the Web tier.
i18n XSLT
locale insert XSLT
l10n XSLT
39
Example Web Tier(after i18n changes)
HTTP request
ActionServlet
CredentialsFilter
To Service Tier
HTTP response
Struts tags
Resource Bundles
HTTP response
MyApp.properties
Xalan-Java
ResourceBundleUtil
40
The Process of i18n
  • i18n (create properties files and remove
    hard-coded values)
  • Send translations to translators
  • Receive translations and perform l10n
  • Deploy and have customers acceptance test

41
Recap
  • i18n, l10n
  • Goals Business Needs, Scalability,
    Maintainability
  • Technical Design J2EE Web Tier and XSLT
  • The Process of Internationalization

42
Questions?
I hope all of your wildest dreams of
internationalizing your app come true. Lucky!
Thank you for attending! Jason
Shepherd jshepherd_at_bass-inc.com 402-346-1505
Write a Comment
User Comments (0)