Chapter 8: Struts and I18N


In this chapter:

  1. You will understand the basics of I18N

  2. You will learn the basics of Java I18N API

  3. You will review the features in Struts for I18N

  4. You will look how Tiles application is I18N enabled

  5. You will understand how localized input is processed

The Internet has no boundaries and neither should your web application. People all over the world access the net to browse web pages that are written in different languages. A user in Japan can access the web and check her Yahoo! Email in Japanese. How does Yahoo do it? Is it because the user ‚ s machine has a Japanese operating system or do web-based applications automatically adjust according to the users ‚ region? This chapter answers these questions and shows you how to internationalize and localize your Struts web applications.

Terminology

Before diving deep into the bliss of Internationalization and Localization, coverage of some basic terminology is essential. That ‚ s what we are doing in this section.

Internationalization or I18n is the process of enabling your application to cater to users from different countries and supporting different languages. With I18n, software is made portable between languages or regions . For example, the Yahoo! Web site supports users from English, Japanese and Korean speaking countries, to name a few.

Localization or L10n on the other hand, is the process of customizing your application to support a specific location. When you customize your web application to a specific country say, Germany, you are localizing your application. Localization involves establishing on-line information to support a specific language or region.

A Locale is a term that is used to describe a certain region and possibly a language for that region. In software terms, we generally refer to applications as supporting certain locales. For example, a web application that supports a locale of ‚“fr_FR ‚½ is enabling French-speaking users in France to navigate it. Similarly a locale of ‚“en_US ‚½ indicates an application supporting English-speaking users in the US.

A ResourceBundle is a class that is used to hold locale specific information. In Java applications, the developer creates an instance of a ResourceBundle and populates it with information specific to each locale such as text messages, labels, and also objects. There will be one ResourceBundle object per Locale.

What can be localized?

When your application runs anywhere in the US, everyone, well almost everyone speaks English and hence, they won ‚ t have any trouble trying to figure out what your application is trying to say. Now, consider the same application being accessed by a user in a country say Japan where English is not the mainstream language. There is a good chance that the very same message might not make much sense to a Japanese user. The point in context is very simple: Present your web application to foreign users in a way they can comprehend it and navigate freely without facing any language barriers.

Great, now you know where this is leading, right? That ‚ s right, localization! In order to localize your web application, you have to identify the key areas that will have to change. There are three such key areas. From a Struts perspective, you only have to deal with the first two.

  1. The visible part of your application ‚ the User Interface. The user interface specific changes could mean changes to text, date formats, currency formats etc.

  2. Glue Layer ‚ Presentation Logic that links the UI to the business logic.

  3. The invisible parts of your application ‚ Database support for different character encoding formats and your back-end logic that processes this data.

Here is a list of the commonly localized areas in a web application. We will de dealing only with the highlighted ones in this chapter.

  1. Messages and Labels on GUI components ‚ labels, button names

  2. Dates and Times

  3. Numbers and Currencies

  4. Personal titles, Phone numbers and Addresses

  5. Graphics ‚ Images specific for every locale and cater to each region ‚ s cultural tastes.

  6. Colors ‚ Colors play a very important role in different countries. For example, death is represented by the color white in China.

  7. Sounds

  8. Page layouts ‚ that ‚ s right. Just like colors, page layouts can vary from locale to locale based on the country ‚ s cultural preferences.

  9. Presentation Logic in Struts Action classes.

There are other properties that you might require to be localized, but the ones mentioned are the commonly used ones. Struts provides mechanisms to address some of these, but the actual I18N and L10N capabilities lie in the Java API itself. You will see in the next section, a brief overview of the Java Internationalization API and some examples on how to update some of these fields dynamically based on Locale information.




Struts Survival Guide. Basics to Best Practices
Struts Survival Guide: Basics to Best Practices (J2ee Survival Series)
ISBN: 0974848808
EAN: 2147483647
Year: 2004
Pages: 96

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net