Core JSTL Mastering the JSPT Standard Tag Library [Electronic resources] نسخه متنی

اینجــــا یک کتابخانه دیجیتالی است

با بیش از 100000 منبع الکترونیکی رایگان به زبان فارسی ، عربی و انگلیسی

Core JSTL Mastering the JSPT Standard Tag Library [Electronic resources] - نسخه متنی

David M. Geary

| نمايش فراداده ، افزودن یک نقد و بررسی
افزودن به کتابخانه شخصی
ارسال به دوستان
جستجو در متن کتاب
بیشتر
تنظیمات قلم

فونت

اندازه قلم

+ - پیش فرض

حالت نمایش

روز نیمروز شب
جستجو در لغت نامه
بیشتر
لیست موضوعات
توضیحات
افزودن یادداشت جدید











7.2 I18N and L10N


Internationalization, often abbreviated as Overview" on page 250.

Localization, often abbreviated as L10N, is the process of adapting an internationalized application to support a specific locale. For the most part, with JSTL, that means creating a set of resource bundles for specific locales.

To develop internationalized Web applications that you can subsequently localize, you must have a basic understanding of locales, resource bundles, Unicode, and charsets, all of which are discussed in the following sections.

Locales


The most basic localization task is identifying geographical, political, or cultural regions, known as locales. Locale constants for countries and languages are defined by the International Standards Organization (ISO). Table 7.1 lists some examples of locale constants for selected countries.






































Table 7.1. Examples of ISO Country Locale Constants

Country


Code


Canada


CA


China


CN


Germany


DE


Iceland


IS


Italy


IT


Mexico


MX


United States


US

For a complete list of country locale constants, see the following http://www.iso.org/iso/en/prods-services/iso3166ma/02iso-3166-code-lists/list-en1l

Table 7.2 lists some examples of language locale constants.






































Table 7.2. Examples of Language Locale Constants

Language


Code


French


fr


Chinese


zh


German


de


Icelandic


is


Italian


it


Spanish


es


English


en

For a complete list of language locale constants, see the following Configuration Settings" on page 230 for more information about specifying configuration settings directly with servlets and life-cycle listeners.


You can also specify a variant for a locale. Variants are vendor- and browser-specific. For example, you can specify the variants WIN for Microsoft Windows or MAC for Macintosh. You can specify a locale variant with the <fmt:setLocale> action's variant attribute; for example, you could specify the Macintosh variant for France French like this: <fmt:setLocale value='fr-FR' variant='MAC'/>. In practice, locale variants are rarely used.

Resource Bundles


As we discussed in "Overview" on page 250, a resource bundle is a collection of key/value pairs. You can specify resource bundles with a properties file or with a Java class.

Properties files are by far the most popular way to specify resource bundles, even though a resource bundle specified as a Java class is more flexible than one specified as a properties file. The reasons for that popularity are simpleproperties files are easier to create than Java classes, and they do not need to be compiled.

Resource bundles, whether they are specified with a properties file or implemented as a Java class, must reside in either the WEB-INF/classes directory or a subdirectory of WEB-INF/classes.

Resource Bundles as Properties Files

Listing 7.7 lists a simple properties file that specifies localized messages in English for a login page.

Listing 7.7 A Properties File That Represents a Resource Bundle


# Application Properties -- English Version
login.window-title=Localized Error Messages
login.first-name=First Name
login.last-name=Last Name
login.email-address=Email Address

In a properties file, lines beginning with the # character are comments. Key/value pairs are specified with this syntax:

key=value. In a properties file, both keys and values are always strings.

Resource Bundles as Java Classes

Listing 7.8 lists a Java class that specifies a resource bundle equivalent to the one represented by the properties file listed in Listing 7.7.

The Java class in the preceding listing extends java.util.ListResource Bundle, which defines one abstract method: getContents. That method returns a two-dimensional array of objects containing key/value pairs.

Specifying a resource bundle with a Java class is more flexible than using a properties file because values are not limited to strings, as is the case for properties files. Also, if you specify a resource bundle with a Java class, you can calculate values, which you cannot do in a properties file. In practice, those features are rarely used, and as a result properties files are the preferred method of specifying resource bundles.

Unicode and Charsets


Internally, the Java programming language uses Unicode to store characters. Unicode is a character coding system that assigns unique numbers for every character for every major language in the world.

Listing 7.8 A Java Class That Represents a Resource Bundle


import java.util.ListResourceBundle;
// Application Properties -- English Version
public class app_en extends ListResourceBundle {
private static final Object[][] contents = {
{ "login.window-title", "Localized Error Messages" },
{ "login.first-name", "First Name" },
{ "login.last-name", "Last Name" },
{ "login.email-address", "Email Address" },
};
public Object[][] getContents() {
return contents;
}
}

Java's use of Unicode means that JSP pages can store and display strings containing all characters found in all of the commonly used written languages. It also means that you can use Unicode escape sequences to represent characters that you may not find on your keyboard; Table 7.3 lists some of those characters.














































Table 7.3. Unicode Escape Sequence Examples

Unicode Escape


Symbol


Description


\u00C0


Á


Capital A, accent grave


\u00C9


È


Capital E, accent acute


\u00C9


Â


Capital A, accent circumflex


\u00A9


©


Copyright symbol


\u0099



Trademark


\u00B6



Paragraph Sign


\u0086



Dagger Symbol

At their most fundamental level, browsers map bytes to characters or glyphs; for example, browsers will map \u00A9 to the copyright symbol. Those mappings are facilitated by a http://www.faqs.org/rfcs/rfc2278l.



































































Table 7.4. Charset Examples

Language


Language Code


Charset(s)


Chinese (Simplified/Mainland)


zh


GB2312


Chinese (Traditional/Taiwan)


zh


Big5


English


en


ISO-8859-1


French


fr


ISO-8859-15


German


de


ISO-8859-15


Icelandic


is


ISO-8859-1


Italian


it


ISO-8859-15


Japanese


ja


Shift_JIS, ISO-2022-JP, EUC-JP


Korean


ko


EUC-KR


Russian


ru


ISO-8859-5, KO18-R


Spanish


es


ISO-8859-15

There is also a single charset that can be used for all languagesthe Listing 7.9 on page 280 for an example of a Web application that uses the UTF-8 charset.



    / 124