Sun Java System Portal Server 7.1 Developer's Guide

Chapter 34 Localization: Properties

This chapter contains the following sections:

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.

Display Profile Properties

The display profile can be modified by using XML files that are input to the dpadmin command. The encoding for display profile XML file is specified using the following XML header at the top of the file:

<?xml version="1.0" encoding="encoding"?>

where encoding is whatever encoding is suitable for the content of the file. Typically, the encoding is UTF-8; but it can also be other native encodings such as SJIS or ISO-8859-1. The DesktopServlet always converts characters internally to Unicode and stores them in the directory using UTF-8.

Every XML fragment must include a XML header and a doctype declaration as shown below:

<?xml version="1.0" encoding="encoding" standalone="no"?>
<!DOCTYPE DisplayProfile SYSTEM "jar://resources/psdp.dtd">

The display profile contains text strings for items such as channel titles and descriptions. These strings can be localized using the ConditionalProperties locale element.

For example, the user information channel is defined by the following element in the display profile:


<Channel name="UserInfo" provider="UserInfoProvider">
	<Properties>
		<String name="refreshTime" value="60" advanced="true"/>
		<String name="title" value="User Information"/>
		<String name="description" value="View/Edit User Information"/>
	</Properties>
</Channel>

ProcedureTo Localize the User Information Channel Display Profile

  1. To localize the user information channel (title and description), the conditional properties tag for the locale must be added. For example, the following modifications must be included (modifications are shown in bold):


    <Channel name="UserInfo" provider="UserInfoProvider">
    	<Properties>
    		<String name="refreshTime" value="60" advanced="true"/>
    		<String name="title" value="User Information"/>
    		<String name="description" value="View/Edit 
    		User Information"/>
    
    			<ConditionalProperties condition="locale" value="fr" >
    
    			<String name="title" value="User Information in French"/>
    
    			<String name="description" value="View/Edit User Information in French"/>
    
    			</ConditionalProperties>
    	</Properties>
    </Channel>
  2. To add this, you need the following sample display profile fragment (stored in file dp-locale.xml).


    <?xml version="1.0" encoding="utf-8" standalone="no"?>
    <!DOCTYPE DisplayProfile SYSTEM "jar://resources/psdp.dtd">
    	<ConditionalProperties condition="locale" value="fr" >
    		<String name="title" value="User Information in French"/>
    		<String name="description" value="View/Edit User Information in French"/>
    	</ConditionalProperties>
  3. Upload the display profile fragment using the psadmin with the add-display-profile sub command.

    See the Command Line Reference for more information on this sub command.