2. Outline
¤ How to internationalize a web app
¤ Distinguish between different localities
¤ Display appropriate message for different localities
¤ Automatically format elements sensitive to locality
¤ References
2
4. Internationalization and
Localization
¤ Internationalization (i18n) is the process of designing an
application so that it can be adapted to various
languages and regions without engineering changes
¤ Localization (l10n) is the process of adapting software for
a specific region or language by adding locale-specific
components and translating text
4
5. Internationalization requirements
¤ To be internationalized, an application should be able to:
¤ Distinguish between different localities
¤ Display appropriate messages and labels for different
localities (using the same executable)
¤ Provide support for new localities without compiling a new
executable
¤ Automatically format elements sensitive to locality (e.g.,
dates)
5
6. Distinguish between different
localities
¤ The Struts framework maintains a standard Locale object
for each user (java.util.Locale)
¤ A Locale object represents a specific geographical,
political, or cultural region
¤ Example: the locale for French-speaking Canadians
is Locale l = new Locale("fr", "CA")
¤ Components that can alter their behavior by locality are
called locale-sensitive
¤ A number of Struts components are locale-sensitive and
make use of the Locale object that the framework
manages for each user
6
7. Display appropriate messages and
labels for different localities (1/2)
¤ Every message that may be displayed in the application
is stored in a separate file, called the resource bundle
¤ Messages can be updated independently from the source
code (and vice versa)
¤ The web app can be localized by a adding resource
bundle for each supported locale, according to a
specific naming convention:
¤ Example: application_it_IT.properties
7
8. Display appropriate messages and
labels for different localities (2/2)
application.properties (snippet)
registerform.email.msg=Invalid e-mail address
application_it_IT.properties (snippet)
registerform.email.msg=Indirizzo e-mail non valido
¤ The same key is used for the element regardless of
locale, but the message it returns may be different
¤ To support another locale, just add a new resource
bundle
8
9. Automatically format elements
sensitive to locality
¤ Elements sensitive to locality, such as dates and
currencies, may be subject to different formatting
¤ Any local-specific pattern is specified in the resource
bundle according to java.text.MessageFormat
conventions
Localizing a date in application.properties
register.welcome.message=Welcome {0}, today is
{1, date, long}
The second argument
is expected to be a
date
9
10. References
¤ Struts 1 In Action, T. N. Husted, C. Dumoulin, G. Franciscus,
D. Winterfeldt, Manning Publications Co.
¤ MessageFormat Javadoc,
http://docs.oracle.com/javase/1.5.0/docs/api/java/text/
MessageFormat.html
10