User's Manual

Chapter 13. Web Applications Tutorial 167
For example, PropertyResourceBundles might appear as follows for a HelloWorld application,
in English, Spanish, and French:
HelloWorldResources_en.properties
hello_world=Hello world!
HelloWorldResources_es.properties
hello_world=Hola todo el mundo!
HelloWorldResources_fr.properties
hello_world=Salut tout le monde!
For dynamic resources, the MessageCatalog class is provided. Dynamic resources are those that
change while the server is running. Most of these have to do with user-contributed content, where
a user can be an administrator of the site or a regular user. For example, if the Categorization
service was internationalized and application users were to be allowed to create categories, the ap-
plication could allow the user to create a category and name it in more than one language, or mark
the category name for translation into the different languages that the application supports. Since this
kind of data is hard to maintain in PropertyResourceBundles, it is stored it in database-backed
MessageCatalogs.
A MessageCatalog is simply a way to store ResourceBundles in the database. To use them,
you create a MixedResourceBundle . This inherits from Java’s ResourceBundle and combines
a PropertyResourceBundle and a MessageCatalog, which have the same base name, into one.
It does this by reading the PropertyResourceBundle from the file system and the MessageCat-
alog from the database.
No code goes into a MixedResourceBundle; all the code is in the superclass itself. A Mixe-
dResourceBundle for the notes application might appear as follows:
package com.arsdigita.notes;
import com.arsdigita.globalization.MixedResourceBundle;
public class NotesResources_en_US extends MixedResourceBundle {}
Note
This MixedResourceBundle is for the base name com.arsdigita.notes.NotesResources and the
Locale en_US. This stems from the ResourceBundle name and indicates the Locale associated
with the ResourceBundle. In this case, this ResourceBundle should contain resources in American
English.
13.4. Accessing Resources
The GlobalizedMessage class is specifically designed to facilitate management and access to lo-
calized resources. This class represents a single globalized resource. It contains the base name of the
ResourceBundle, which contains the resource and the key to use to lookup the resource, and an
optional array of arguments to interpolate into the localized resource using Java’s MessageFormat