localizing j2ee web applications tony jewtushenko principal product manager lrc localisation summer...

Post on 18-Dec-2015

217 Views

Category:

Documents

2 Downloads

Preview:

Click to see full reader

TRANSCRIPT

Localizing J2EE Web Applications

Tony Jewtushenko

Principal Product Manager

LRC Localisation Summer School, June 2004

Internationalization

“Internationalization is the process of generalizing a product so that it can handle multiple languages and cultural conventions without the need for redesign. Internationalization takes place at the level of program design and document development.” 1

AKA: Internationalisation – UK Spelling and i18n.

1 LISA: Localisation Industry Standards Assoc.

Localization

“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.” 1

AKA: Localisation - the UK English spelling and L10n - the techie contraction

1 LISA: Localisation Industry Standards Assoc.

Multilingual Application Basic Concepts

Data representation: charter set support Data manipulation: collation, direction of text

and internal representation Data display: display strings, currency,

number, date formats weights and measures Data input: understand the format of the data

submitted to the application

Stages of a Multilingual Development Process

Internationalization Localization

– Identify / isolate / extract– Translation– Re-use Translations (optional)

What’s Localized in Web Applications:

Titles Button Text (UIX) Button Graphics / Text (JSP) Links Labels HTML and XML Markup Error and validation messages Database Row or Column names Hint (balloon) text Help

Date Formats Date Pickers Numeric Formats

– Currency– Numbers– Percents

Message Formatting

J2EE: “Java 2 Platform Enterprise Edition”

Sun’s Java-centric platform independent environment for developing, building and deploying Web-based enterprise applications.EJB, JSP, JAX-RPC, Java Servlets, J2EE Connector Architecture, J2EE Management Model, J2EE Deployment API, JMX, J2EE Authorization Contract for Containers, JAXR, JMS, JNDI, JTA, CORBA, and JDBC data access API.

J2EE: Key Benefits

Rapid development Support for Web services Standardized connectivity to existing data

sources and applications Platform independence – no “vendor lock-in”

MVC Design Pattern

MVC = Model / View / Controller– Model components maintain backend

data– View provides end user presentation

layer– Controller provides page flow logic,

and validation

MVC Web Application Architecture

Web Browser

UIController Model

View

DB or

Remote

System

1

45

32

Jakarta Struts

Created in 2000 Current version = 1.1 Open source J2EE applications development

framework Primarily based on JSP and Servlet technology. Subproject of Apache Jakarta Supports MVC Model 2 architecture

– View and Controller are separated– Cleanly separates page design from underlying Java

code

Oracle J2EE Application Development Framework (ADF)

Swing ADF UIX JSF

Struts

ADF Model

WebServices

EJBSession

Beans

ADFBusiness

Components

JavaBeans/Other

View Swing JSPJSP ADF UIX

Controller

Model

BusinessServices

Rich Client Web Client

Exercise 1Create a Basic JSP

Page

Exercise 2Create a Basic UIX

Page

Challenges in J2EE i18n

Encoding – Locale specific character set support

Messaging – Isolation and Translation of UI resources such as text

Formatting – Handling input and output of locale conventions for formatting of numbers, dates, currency

Encoding in J2EE

JSP is Java, so Unicode is used internally, but… 3 types of encoding must be considered for JSP’s

Request: – Encoding in which parameters in an incoming request are

interpreted.

Page (JSP pages)– the encoding of the bytes in the JSP page itself. If not set,

encoding defaults to contentType charset attribute setting.

Response– encoding to be used for generated web pages, based on the

capabilities of the targeted browsers.

Request Encoding

Parameters submitted as byte values, in the specified charset

Set automatically to Accept-Language header using:

<fmt:requestEncoding/> or first i18n action

Or set explicitly with<fmt:requestEncoding value=“UTF-8”/>

Page Encoding

Usually determined by editing tools conventions Set in page directive

<%@ page pageEncoding=“Shift_JIS” contentType=“text/html;charset=UTF-8” %>

– Must be extension of ASCII charset (ie, no EBCDIC or UTF-16) so UTF-8 is OK

– If not explicitly set, defaults to contentType charset attribute value, but recommended to explicitly set

Response Encoding

Identifies the encoding of the generated web page Set in contentType attribute

<%@ page pageEncoding=“Shift_JIS” contentType=“text/html;charset=UTF-8” %>

Exercise 3

Encoding

Java ResourceBundles: Localizable content

ListResourceBundle– .java file– Can contain binary data– Compiled into class file

PropertyResourceBundles– .properties file– Contain strings only– Values acquired at runtime– Requires 8859-1 encoding– Non 8859-1 characters represented as

UTF8 escape codes (ie, \uxxxx)– native2ascii to convert non 8859-1

content

ResourceBundle Search Algorithm (baseclass)+(specific language)+(specific country)+(specific variant)

(baseclass)+(specific language)+(specific country)

(baseclass)+(specific language) (baseclass)+(default language)+(default country)+(default variant)

(baseclass)+(default language)+(default country)

(baseclass)+(default language)

ResourceBundle and Locale

greeting-evening=Hello

ApplicationResources

fr_CA_UNIX

greeting-evening= Bonsoir

ApplicationResources_fr

greeting-evening=Good Evening

ApplicationResources_en_GB

JSP

ResourceBundle

Oracle ADF ResourceBundle Implementation

ListResourceBundle– Model entity properties such as Column names,

Hint Text, custom messages– Validation Errors

PropertyResourceBundle– All text, titles, etc.– E.g., button text, headers, titles, error

messages– Slightly slower performance than

ListResourceBundle

Localizing ListResourceBundles

1. Subclass the base java ResourceBundle2. Append the constructor with language

suffixe.g., public MyMsgBundle_es()

3. Translate all strings, modify format masks, etc

4. Recompile, explicitly specifying character encoding if other than ISO8859-1

package model.common;import oracle.jbo.common.JboResourceBundle;// ---------------------------------------------------------------// --- File generated by Oracle Business Components for Java.// ---------------------------------------------------------------public class PmViewRowImplMsgBundle_es extends PmViewRowImplMsgBundle{ /** */ public PmViewRowImplMsgBundle_es() { } /** * * @return an array of key-value pairs. */ public Object[][] getContents() { return super.getMergedArray(sMessageStrings, super.getContents()); }

static final Object[][] sMessageStrings = { {"PmId_LABEL", "Número de identificación"}, {"Email_LABEL", "Dirección del Correo Electrónico"}, {"Phone_LABEL", "Número De Teléfono"}, {"Jobtitle_LABEL", "Título Del Trabajo"}, {"Pmname_LABEL", "Nombre del P.M."}};}

A Translated ListResourceBundle

Translating PropertiesResourceBundles:

Create language / locale specific properties files in the same location as base properties file

– E.g., create:

ApplicationsResources_es.properties– in same directory as base file:

ApplicationsResources.properties• Add keys and translated values • Any keys not found in language/locale subclass

will inherit values from the base class values

Exercise 4

Creating and Localizing a ListResourceBundle

PropertiesResourceBundles and Character Sets:

Properties files may only contain characters in the ISO 8859-1 character set.

Important: all non-8859-1 character sets must be converted to escaped UTF-8 characters, or they will appear corrupt in the browser!1. After translating text files, save to native properties file

(text file)

2. Convert to Unicode Escaped characters (i.e., € = \u20ac) by using the “native2ascii” utility in the JDK (ie, native2ascii –encoding UTF8 Errors_ja.properties

Errors_ja_88591.properties)

errorpage.title=Página Del Errorerrorpage.apperror=Error Del Usoerror.Validate3=<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{0}</li>error.Validate2=<li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{0}</li>error.Validate1=<li>&nbsp;&nbsp;&nbsp;{0}</li>error.Validate0=<li>{0}</li>errors.header=<h3><font color\="red">Error De la Validación</font></h3>Usted debe corregir el error(es) siguiente antes de proceder\:<ul>errors.prefix=<li>globalerror.jboException=Error Del Usoerrorpage.message=Mensaje De Error\:errors.footer=</ul><hr>errors.suffix=</li>

titleGlobal=Acontecimientos De la Gerencia De ProductotitleBrowseEvents=Hojee Los Acontecimientos (Página Principal)titleAddPaper=Agregue El PapeltitleSelectAnd=Seleccione y

globalbuttonBrowsePM=Hojee los PMglobalbuttonBrowsePaper=Hojee Los PapelesglobalbuttonBrowseEvent=Hojee Los Acontecimientos

buttonSubmit=SometabuttonCancel=CancelaciónbuttonAdd=AgreguebuttonDelete=QuitebuttonEdit=Corrija

A Translated PropertyResourceBundle

Exercise 5

Creating and Localizing a PropertyResourceBundle

Multi-lingual Web Application Design Considerations

Typical Multilingual Implementations: Clone & Translate User Selects Language / Locale at Home

Page Language / Locale Set to Browser preferred

Language/Locale Settings Repository based locale preference lookup

Design Option: Clone and Translate

en_US ja_JP es_ESfr_FR

Index.jsp Index.jsp Index.jsp Index.jsp

Design Option: One JSP / Multiple Languages

Index.jsp

Resources.properties

Resources_es_ES.properties

Resources_ja_JP.properties

Resources_fr_FR.properties

Design Option: One JSP per language, w/ResouceBundles

Index.jsp

Resources.properties

Resources_es_ES.properties

Resources_ja_JP.properties

Resources_fr_FR.properties

Index_es.jsp

Index_ja.jsp

Index_fr.jsp

Exercise 6

Create Page with User Selected Language

JSTL – JavaServer Pages Standard Tag Library

Collection of standard JSP actions Latest version 1.1 Main libaries:

– XML processing support: “xml” library– SQL DBMS access: “sql” library– Variable manipulation, flow control, URL

actions: “core” library– I18n and formatting: “fmt” library

JSTL – i18n Tags I18n and L10n support Prefix = fmt Support for:

– Setting locale context– Fetching locale context sensitive content– Handling locale specific numeric and date formatting

Many functions reused by other tag libraries:– Struts <bean:message> tag– Jakarta i18n Tags

At top of JSP, specify the tag library directive :<%@ taglib uri="http://java.sun.com/jstl/fmt"

prefix="fmt"%>

JSTL Locale

<fmt:setLocale value=“en_IE" scope="session" />

– Scope default is “page”– Optional variant attribute

<fmt:requestEncoding value=“UTF-8”/>

– value attribute is optional

JSTL Resource

Set the base bundle:<fmt:setBundle basename=“strings” scope=“session”/>

Replace the hard coded strings in the JSP with the <fmt:message>

<fmt:message key="buttonsubmit"/>

Pass parameters:<fmt:message key=“Totals">

<fmt:param value=“${subtotal_1}”/>

<fmt:param value=“${subtotal_2}”/>

</fmt:message>

JSTL Format

Format date for output:<fmt:formatDate value=“${now}” type=“date”

datestyle=“short”/>

Parse submitted date<fmt:parseDate value=“${param.birthday}” type=“date”

pattern=“yyy-MM-dd”/>

Format Numbers<fmt:formatNumber value=“200.00” type=“currency”

currencySymbol=“£”/>

Parse Numbers<fmt:parseNumber value=“${param.carPrice”}

type=“currency” parseLocale=“en_IE”/>

Struts <bean> tag

The same as JSTL <fmt:message> tag Configure ResourceBundle location in Struts-

Config.xml file<message-resources

parameter="view.ApplicationResources"/>

At top of JSP, add this directive:<%@ taglib uri="/WEB-INF/struts-bean.tld"

prefix="bean“%>

Then replace hard coded strings with <bean:message key="empmaintitle"/>

Jakarta i18n tag Library

i18n tags similar to Struts “message” tag, but more robust

Use in JSP’s - Struts not required Includes many JSTL i18n tags I18n Management Tags:

– Ifdef, Ifndef, Locale, Message, Bundle, MessageArg

Formatting Tags:– FormatDateTime, FormatDate, FomatTime,

FormatCurrency, FormatPercent, FormatNumber, FormatString

Specifying location of resources in Struts / JSP Define message file locations in struts-config.xml A <message-resources> element with no key

attribute defines the default message resource. Secondary message resources identify their key by

specifying a value for the key attribute.<struts-config>    :  <!--   | This entry tells Struts where to find the default application   | resources properties file   +-->  <message-resources parameter=“view.ApplicationResources"/>  <!--   | Resource used to render globals errors with <html:errors>   +-->  <message-resources key="GlobalErrors" parameter=“view.GlobalErrors"/></struts-config>

PropertyResourceBundles in Struts/JSP

PropertiesResourceBundles may be referenced in the JSP page by using <bean:message> tag:

<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %><html> <head> <title><bean:message key="accountcreated.title"/></title> </head> <body> <jsp:include page="header.jsp" flush="true"/> <jsp:include page="navbar.jsp" flush="true"/> <h2><bean:message key="accountcreated.header"/></h2> <br><br> <a href="home.do"><bean:message key="accountcreated.gotomainpage"/></a> </body></html>

PropertyResourceBundles and JSTL / Struts / JSP

Declare the custom JSTL library in the JSP header

<fmt:bundle> defines resource location within <body>. Optional “prefix” attribute simplifies key name

<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c"%><%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html"%><%@ page contentType="text/html;charset=UTF-8"%><%@ taglib uri="http://java.sun.com/jstl/fmt" prefix="fmt"%><html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"></head><body><fmt:bundle basename="view.ApplicationResources" prefix='header.'> <H1><fmt:message key='maintitle'/></H1>

...</fmt:bundle> </body></html>

<fmt:message> specifies the resources

Exercise 7

Internationalize and Localize JSP using tags

Oracle ADF-UIX ComponentsPre-translated content - Over 30 languages supported

Loads resources based on browser setting

Limit language support by configuring uix-config.xml

<supported-locales>

<default-locale>en-US</default-locale>

<supported-locale>es</supported-locale>

</supported-locales>

Simplifies development, i18n, l10n

Extends Java Server Faces

Seamless upgrade to full JSF

<?xml version="1.0" encoding=“UTF-8"?><page xmlns="http://xmlns.oracle.com/uix/controller" xmlns:ui="http://xmlns.oracle.com/uix/ui" xmlns:ctrl="http://xmlns.oracle.com/uix/controller" xmlns:html="http://www.w3.org/TR/REC-html40" expressionLanguage="el"> <content> <dataScope xmlns="http://xmlns.oracle.com/uix/ui"> <provider> <data name="nls"> <bundle class="view.ApplicationResources"/> </data> </provider> ... <metaContainer> <!-- Set the page title --> <head title="${uix.data.nls.titleGlobal}"/> </metaContainer> ...

PropertyResourceBundles in Struts / ADF UIX

Define provider in each UIX file

Reference using ${uix.data.<provider>.<key name>}

Exercise 8

Internationalize and Localise a UIX Page

JDeveloper 10g IDE L10N Features

Real-time access to resource bundles

package model.common;import oracle.jbo.common.JboResourceBundle;// ---------------------------------------------------------------------// --- File generated by Oracle ADF Business Components Design Time.// --- Custom code may be added to this class.// ---------------------------------------------------------------------public class EmployeesImplMsgBundle extends JboResourceBundle{ /** * * This is the default constructor (do not remove) */ public EmployeesImplMsgBundle() { } /** * @return an array of key-value pairs. */ public Object[][] getContents() { return super.getMergedArray(sMessageStrings, super.getContents()); } static final Object[][] sMessageStrings = { {"Salary_FMT_FORMAT", "$ #,##,###,####.00"},

JDeveloper 10g IDE L10N Features

Generates List Resource Bundle from Entity Editor

Large Project Considerations

Include i18n and l10n in design phase Commence i18n and l10n work early Create a separate properties files for each module /

subsystem Never check in code with static text Implement Pseudo Translation test cycle early in the

development project cycle, and repeat often. Reuse previous translations using commercial

Translation / Localisation tools

L10n Productivity Toolse.g., Alchemy Software Catalyst 5.0

Localization Tool Features- Pseudo Translation

Most L10n tools support the validation of the internationalization of your application by Pseudo Translating it. Pseudo Translation enables your development team to run a test cycle early in the development project cycle, before a single word is translated.

Localization Tool Features- Resource Format Support

Ensure the tool you choose correctly interprets resource bundles.Most tools provide customizable input and output filters which can easily support both PropertiesResourceBundles and ListResourceBundlesConsider transforming resources to / from XLIFF, the XML Localization Interchange File Format emerging standard (www.xliff.org)

Localization Tool Features- Translation Memory

3rd party localization tools will often provide tools for reusing previous translations when your project changes. Frequently retranslating your strings when versions change is a needless expense. Translation Memory provides reuse of existing translations.

Localization Tool Features - Automation

Automation and scripting are important when you need to maintain consistency of your process across many different languages, or when you have many individual files being sent out to translators as well as translations coming back in that must be integrated into your application.

AQ&

Resources for further study Oracle Tech Net Whitepaper:

http://otn.oracle.com/products/jdev/collateral/papers/10g/jdev10g_multilingual.pdf

“The Multilingual World Wide Web“, Gavin Nicol, http://www.oasis-open.org/cover/nicol-multwww.html

W3C: http://www.w3c.org/international “Best Practices in Internationalizing Web-Based

EnterpriseApplications”, Greg Murray: http://java.sun.com/javaone/javaone2001/pdfs/2335.pdf

“J2EE Internationalization and Localization”, Greg Murray: http://java.sun.com/blueprints/guidelines/designing_enterprise_applications_2e/i18n/i18n5.html

Oracle Resources

Oracle Technology Network:

http://otn.oracle.com Download Jdeveloper 10g

http://otn.oracle.com/software/products/jdev/index.html

JDeveloper 10g White papers, samples, product information: http://otn.oracle.com/products/jdev/index.html

top related