Title: Java Internationalization
ISBN: 0596000197
US Price: $ 39.95

© 2001 O'Reilly & Associates, Inc.

Reviews : Java Books :
Java Internationalization : Isolating Locale-Specific Data With Resource Bundles

Chapter 4
Isolating Locale-Specific Data with Resource Bundles

Error messages, status messages, graphic images, and even sound clips are perfect examples of candidate elements for localization. For instance, all text messages displayed to users throughout your program first need to be translated, or localized, for the locales that you're going to support. This task can be very time consuming and costly. After completing the task, how do you package these messages together so the proper locale- specific information gets displayed to the user?

Java's ResourceBundle class provides the functionality for you to retrieve locale-specific resources. You can use resource bundles in your application to keep text messages, formatting conventions, images, sound files, etc., in a "package" targeted to different locales. It is possible to use the ResourceBundle class by providing your own subclass; however, two concrete implementations of ResourceBundle exist: PropertyResourceBundle and ListResourceBundle. These two classes provide additional functionality over the base ResourceBundle class.

Why Use Resource Bundles?

Applications need to provide locale-sensitive information to users. One approach is to hardcode locale-sensitive information or messages within the application. However, this approach is inefficient because it makes your application larger, complicates your application logic when you decide which messages to display, and requires that you change or release a new version of your application when locale-specific resources change. Another approach, Java resource bundles, provides facilities for packaging and managing collections of locale-specific elements, such as feedback or status messages. These elements may also be more complex datatypes, such as graphic images or sound files. The resource bundle facilities provide a convenient mechanism for you to separate your program code from your resource data.

Let's outline some general resource bundle properties. These properties are illustrated in Figure 4-1. Resource bundles:

  • Provide facilities for storage and retrieval of all locale-specific information.
  • Allow you to support multiple locales in a single application.
  • Allow you to support additional locales easily in the future by simply adding more resource bundles.


Figure 4-1. How resource bundles fit into application development

How to Add Java Applets to Your Site

New on the Java Boutique:

New Review:

Time Management Made Easy with the Quartz Enterprise Job Scheduler
Why not just use the Java timer API? This open source scheduling API boasts simplicity, ease-of-integration, a well-rounded feature set, and it's free!

New Applet:

Reverse Complement
Reverse Complement is a simple applet that converts DNA or RNA sequences into three useful formats.

Elsewhere on internet.com:

WebDeveloper Java
Lots of Java information on webdeveloper.com

WDVL Java
Thorough Java resource at the Web Developer's Virtual Library.

ScriptSearch Java
Hundreds of free Java code files to download.

jGuru: Your View of the Java Universe
Customizable portal with online training, FAQs, regular news updates, and tutorials.