Sun Java System Portal Server 7.1 Developer's Guide

Resource Bundles

This section contains:

Introduction to Resource Bundles

Resource bundles contain locale-specific objects. When your program needs a locale-specific resource, a String for example, your program can load it from the resource bundle that is appropriate for the current user’s locale. See the documentation on Resource Bundles at http://java.sun.com/products/jdk/1.2/docs/api/java/util/ResourceBundle.html for more information on:

The Desktop and the Desktop Providers use Java Resource Bundles for the localized on screen text.

Resource bundle for providers store content that is not included in display templates (such as error messages and dynamic content). The Portal Server software automatically loads the correct resource bundle for the user’s locale (see Resource Bundle Access for more details).

File Naming Convention

The file name for the resource bundle is usually the provider name, that is, the name defined in the display profile when the provider class is declared. For example:

<Provider name="Bookmark" class="com.iplanet.portalserver.
providers.bookmark.BookmarkProvider">

Here, for the BookmarkProvider, the resource bundle file name is Bookmark.properties. The provider name will be retrieved via the ProviderContext.getProviderName() method.

The provider can also use a different name (different from the default name) for the resource bundle. The name must be passed as a key when calling ProviderAdapter.getResourceBundle(String key) method.

File Installation Location

The resource bundle files must be installed in the /var/opt/SUNWportal/portals/portal-ID/desktop/classes directory. For each X.properties file, create a X_locale.properties file that contains the translation. The translated file must be installed into the same directory as the English version.

File Entries Format

Each line of the properties file uses the format key=value. Lines can be continued using a backslash (\\) at the end of the line. The .properties files are encoded using Java Unicode encoding where non-ASCII characters are represented using \\uXXXX notation. Here, the \\uXXXX is the hexidecimal representation of the Unicode value for the character. This type of file can be created from a native file using the Java native2ascii program available in the JDK 1.3.1 package that is installed in the JDK_DIR directory specified in /etc/opt/SUNWps/PSConfig.properties file.

The messages represented by the value part of the line are formatted using the conventions of the Java java.text.Message format class. See the Javadocs for this class for more details on how to express parameters within messages. Parameters are enclosed in curly braces ({}).

Resource Bundle Access

The ProviderAdapter.getResourceBundle() method loads the correct resource bundle for the user’s locale and if the specified locale is not found, it loads the default resource bundle. That is, it will look for the providerName_locale.properties file; if it is unable to find the specified properties file, it will look for providerName.properties file and load it.