The following class provides developers with the ability to isolate locale-specific resources from a resource bundle. This class significantly simplifies localization and translation:
public abstract class ResourceBundle extends Object
Creating resource bundles needs a purposeful approach. For example, let's imagine that we are creating a resource bundle that will support multiple languages for a business application. Our button labels, among other things, will be displayed differently depending on the current locale. So, for our example, we can create a resource bundle for our buttons. We can call it buttonResources. Then, for each locale, we can create buttonResource_<identifier>. Here are some examples:
- buttonResource_ja: for Japanese
- buttonResource_uk: for UK English
- buttonResource_it: for Italian
- buttonResource_lh: for Lithuanian
We can use a resource bundle with the same name as the base name for our default bundle. So, buttonResource would contain our default bundle.
To obtain a locale-specific object, we make a call to the getBundle method. An example follows:
. . .
ResourceBundle = buttonResource =
ResourceBundle.getBundle("buttonResource", currentLocale);
. . .
In the next sections, we will examine the ResourceBundle class by looking at its nested class, field, and constructor, and included methods.