270 likes | 797 Views
Internationalization and Localization. Celsina Bignoli bignolic@smccd.net. Internationalization and Localization. internationalization : creating code so that it can be customized for use in different countries and regions ( i18n-ready)
E N D
InternationalizationandLocalization Celsina Bignoli bignolic@smccd.net
Internationalization and Localization • internationalization: creating code so that it can be customized for use in different countries and regions ( i18n-ready) • localization: adapting i18n-ready software to a particular region(i10n-ready) • translating text to the local language • changing numeric formatting • changing currency symbols • changing date formatting
Per-request Localization Browser User from US Localized UI in English Browser User from China Central Web Server (US) Localized UI in Chinese Internationalized JSP based Web Application Browser User from France Localized UI in French
Locales • represents a specific set of localization requirements • Specified using a string in the following format xx_YY • xx is the language code • YY is the code of the country that uses that language • Examples: en_GB, en_US, es_MX, es_ES
Maintaining Locale Information • On a standalone Java application running on a single system, the locale can be set by the underlying OS • For web applications the locale of the server machine is of no significance • localization must be determined and handled on a per-request basis • Explicit locale determination
Java 2 Resource Bundles • The application does not contain any text strings that might need to be translated • Instead, specific names are given to these strings • A resource bundle is created as a set of property files • Each line in a property file has the following format: <property name> = <property value> • A property file is created for each language supported (app.properties, app_es.properties, app_zh.properties etc) • Property names are the same in each property file, property value is language specific • .properties files are located in WEB-INF/classes
JSTL fmt Library • JSTL tags to support i18n are located in the fmt tag library • This tag library must be included in a JSP page as follow: %@taglib prefix=“fmt” uri=“http://java.sun.com/jsp/jstl/fmt” %
<fmt:setLocale> • sets the locale configuration variable establishing thr locale for all other JSTL actions that rely on it • Syntax: <fmt:setLocale value=“locale” [scope=“page|request|session|application] />
<fmt:bundle> • sets a localization context for actions in its body • The localization context contains a locale and the best match for the specified resource bundle • Syntax: <fmt:bundle basename=“resourceBundleBasename” [prefix=“keyPrefix”]> JSP elements </fmt:bundle>
<fmt:message> • adds the localized message for the specified key to the response buffer or saves it into a scoped variable • Syntax: <fmt:message key=“messageKey” [bundle=“resourceBundle”] [var=“var” [scope=“page|request|session|application]] />
<fmt:formatNumber> • formats a numeric value according to the given locale • Syntax: <fmt:formatDate value=“number” [pattern=“pattern” | [type=“number|currency|percent”] [currencyCode=“currencyCode”] [currencySymbol=“currencySymbol”] [groupingUsed=“true|false”] [minIntegerDigits=“min”] [maxIntegerDigits=“max”] [minFractionDigits=“min”] [maxFractionDigits=“max”] [[var=“var” [scope=“page|request|session|application]] />
<fmt:formatDate> • formats a date and time value according to the given locale • Syntax: <fmt:formatDate value=“dateAndTime” [pattern=“pattern” | [type=“time|date|both”] [dateStyle=“default|short|medium|long|full”] [timeStyle=“default|short|medium|long|full”]] [timeZone=“timeZone”] [[var=“var” [scope=“page|request|session|application]] />
<fmt:timeZone> • establishes the time zone for actions in its body • Syntax: <fmt:timeZone value=“timeZone”> JSP elements </fmt:timeZone>
<fmt:setTimeZone> • sets the time zone configuration variable for all JSTL actions that rely on it. • Syntax: <fmt:setTimeZone value=“timeZone”> [var=“var” [scope=“page|request|session|application]] />