Java Reference
In-Depth Information
24.2. Resource Bundles
When you internationalize code, you commonly have units of meaning-
such as text or soundsthat must be translated or otherwise made appro-
priate for each locale. If you put English text directly into your program,
localizing that code is difficultit requires finding all the strings in your pro-
gram, identifying which ones are shown to users, and translating them
in the code, thereby creating a second version of your program for, say,
Swahili users. When you repeat this process for a large number of locales
the task becomes a nightmare.
The resource bundle classes in java.util help you address this problem
in a cleaner and more flexible fashion. The abstract class ResourceBundle
defines methods to look up resources in a bundle by string key and to
provide a parent bundle that will be searched if a bundle doesn't have
a key. This inheritance feature allows one bundle to be just like anoth-
er bundle except that a few resource values are modified or added. For
example, a U.S. English bundle might use a U.K. English bundle for a
parent, providing replacements for resources that have different spelling.
ResourceBundle provides the following public methods:
public final String getString(String key) tHRows MissingResourceEx-
ception
Returns the string stored in the bundle under the given key .
public final String[] getStringArray(String key) throws MissingRe-
sourceException
Returns the string array stored in the bundle under the given
key .
public final Object getObject(String key) throws MissingResourceEx-
ception
Returns the object stored in the bundle under the given key .
 
Search WWH ::




Custom Search