Java Reference
In-Depth Information
the bundle name. If even that bundle does not exist,
getBundle
throws a
MissingBundleException
.
For example, suppose you ask for the bundle
GlobalRes
, specifying a loc-
ale for an Esperanto speaker living in Kiribati who is left-handed, and the
default locale of the user is for a Nepali speaker in Bhutan who works
for Acme, Inc. The longest possible search would be:
GlobalRes_eo_KI_left
GlobalRes_eo_KI
GlobalRes_eo
GlobalRes_ne_BT_Acme
GlobalRes_ne_BT
GlobalRes_ne
GlobalRes
The first resource bundle that is found ends the search, being considered
the best available match.
The examples you have seen use resource bundles to fetch strings, but
remember that you can use
getObject
to get any type of object. Bundles
are used to store images,
URL
s, audio sources, graphics components,
and any other kind of locale-sensitive resource that can be represented
by an object.
Mapping string keys to localized resource objects is usually straight-
forwardsimply use one of the provided subclasses of
ResourceBundle
that implement the lookup for you:
ListResourceBundle
and
PropertyRe-
sourceBundle
.
24.2.1.
ListResourceBundle
ListResourceBundle
maps a simple list of keys to their localized objects. It
is an abstract subclass of
ResourceBundle
for which you provide a
getCon-
tents
method that returns an array of key/resource pairs as an array