Your Java application can make use of resource bundles, to provide different localized versions of the text used on your JSP pages.
Resource bundles contain locale-specific objects. When your program needs a locale-specific resource, such as some text to display on a page, your program can load it from the resource bundle that is appropriate for the current user locale. In this way, you can write program code that is largely independent of the user locale isolating the actual text in resource bundles.
In outline, the resource bundle technology has the following features:
Resource bundles belong to families whose members share a common base name, but whose names also have additional components that identify their locales. For example, the base name of a family of resource bundles might be MyResources
. A locale-specific version for German, for example, would be called MyResources_de
.
Each resource bundle in a family contains the same items, but the items have been translated for the locale represented by that resource bundle. For example, a String
used on a button might in MyResources
be defined as Cancel
, but in MyResources_de
as Abbrechen
.
You can make specializations for different resources for different countries, for example, for the German language (de
) in Switzerland (CH
).
To use resource bundles in your application, you must do the following:
In the sample application, resource bundles can be used in the following places:
Headings and labels on JSP pages. In this case, rather than entering text directly on the pages, you can use a scriptlet to find the text.
Values for buttons and other controls. In this case, set the value
property of the button to an expression that retrieves the text from the resource bundle
This section covers the following tasks: