Using Locale Resources

Web Application Toolkit provides locale resources for client-based, multicultural support in your applications. To support locales in a client, the controller framework gets the client locale from each browser request, and returns an HTML page in the language specified in the request. Therefore, users of various languages are supported—provided that you translate your application's UI strings in the various languages of your users.

Web Application Toolkit includes the following resources for multicultural support:

This topic consists of two parts. The first, How Locale Resources are Retrieved, gives you a conceptual understanding of the Toolkit's locale support. The second, Working with Locale Resources, provides guidelines and procedures for working with locale resource strings.

Note that any customization that involves locale resource strings requires an understanding of the Toolkit's locale support—even if you will not be translating resource bundles to another language.

How Locale Resources are Retrieved

Code components that generate a UI (Java, Java™ Server Pages (JSP), XML, XSL) use WcmString and WcmException to retrieve locale-specific UI strings from a resource bundle. The following diagram shows a simplified view of the process, where a locale value is retrieved using a key prefixed with "server".

How a locale value is retrieved.

A component requiring a locale-specific string creates an instance of WcmString or WcmException, for example:

private static final WcmString wsInstructions =
new WcmString("server.WcmInstructions.instructionsLink", "Instructions");
...
w.write("<a class='wcmInstructionLink' href=\"" +sFullEventURL = \"" +
wsInstructions.toString(locale) + "</a>");

WcmString and WcmException retrieve locale-specific UI strings from resource bundles using keys.

Property resource bundles are organized by key prefix and language.

A property resource bundle contains key/value pairs of string resources, for example:

server.MultiValuePageSelect_jsp.Available=Available Pages
server.WcmInstructions.instructionsLink=Instructions
server.PrefSiteGeneralInfoPage.application=Application

In the above diagram, a WcmString object is created with a key and a default string. The object's toString() method gets the locale-specific string from an English language resource bundle. (If there is no matching key in the resource bundle, then the default string in the WcmString constructor is used.)

Note that if the locale passed to the toString() method were Italy, then WcmString would attempt to get the locale-specific string from an Italian language resource bundle, for example:

server.WcmInstructions.instructionsLink=Istruzioni

WcmException is the functional equivalent of WcmString. Whereas WcmString retrieves locale-specific UI strings, WcmException retrieves locale-specific error strings from exception resource bundles. In the following code snippet, a WcmException object is created with a lookup key, a resource string, and an argument "{0}" to concatenate to the resource string:

if (nodeAttachment == null)
throw new WcmException(locale, "server.WcmEProcessUtil.noAttachment",
"Unknown attachment: {0}", attachmentName);

NOTE  The above examples show the locale being passed to WcmString and WcmException. If you don't specify a locale in your calls, the server locale will be used.

Let's look more closely at resource bundles and the locale utility classes that access them.

Property Resource Bundles

Locale Utility Classes

Working with Locale Resources

This section provides guidelines and procedures for working with locale resource strings. Refer to the subsections applicable to your resource string requirements.

Obtaining the Client Locale

The controller framework does the work of getting the locale from a client request and provides methods for your application to retrieve it. We recommend three approaches based on the following module types: Java, JSP and Servlet, or XSL.

Specifying the Locale

You specify the client locale using the following constructors and methods in the WcmString and WcmException utility classes:

NOTE  Due to a GlobalParser restriction, the variable name for a locale used in constructors and the WcmString.localize(…) methods must be named locale.

Key-Naming Guidelines

To avoid duplicate locale keys in your source code, follow these key-naming guidelines for UI strings and exception strings in your source.

Specify your keys with dot "." syntax as follows:

      groupName.className|fileName.label

where:

Generating Resource Bundles

The Toolkit includes ResourceParser, a Java utility that generates the property resource bundles and property list files from all source files that request locale-specific UI and exception strings (Java, JSP, XML, and XSL files). You can generate property resource bundles for a specified source file or for all source files in a specified directory tree. The generated files are in the U.S. English language version.

ResourceParser creates and names the property resource bundles based on the key group name, in this dot syntax format:

groupName.strings.en.US.prb AND groupName.exceptions.en.US.prb

where:

groupName is a developer-defined key prefix in the source. For example, if your source requests UI and exception strings with keys prefixed with "custom", two of the property resource bundles generated by ResourceParser would be custom.strings.en.US.prb and custom.exceptions.en.US.prb.

The property list files generated by ResourceParser are WcmStringConfiguration.en.US and WcmExceptionConfiguration.en.US.

ResourceParser.class is in the tools package and is distributed in <app_root>/WEB-INF/lib/p8toolkit.jar.

To run ResourceParser:

From a command line window, enter the following Java command:

java tools.ResourceParser sourceRoot outputDir

where:

sourceRoot is the name of a single source file to be parsed, or the top level of a directory tree, for example, custom/source. If you specify a directory, all source files in the tree will be parsed.

outputDir is the location where the property resource bundles and the property list files will be created.

For example:

java -classpath p8toolkit.jar tools.ResourceParser
java/src
java/classes/com/filenet/wcm/toolkit/util

If there are existing property resource bundles and property list files in the target path, then ResourceParser will update the applicable property resource bundles with any new key / value pairs. If the key group name is new, ResourceParser will create new property resource bundles based on the key group name; it will also add the names of the new resource bundles to the property list files.

NOTE  The resource bundles for the FileNet P8 Workplace application exist in the same package as WcmString.class and WcmException.class (com.filenet.wcm.toolkit.util), and are loaded statically (implicitly) at runtime. We recommend that you generate your custom resource bundles to a different package, and load them explicitly as described in Loading Resource Bundles at Runtime.

ResourceParser also generates report files, dupkeys.txt, dupvalues.txt, and allvalues.txt. The dupkeys.txt file identifies duplicated keys, that is, keys to which multiple values are assigned. For example, the following listing identifies a key—"server.DocumentPolicy.NoObject"—to which two different values are assigned (the difference is the initial case of the word "object").

"server.DocumentPolicy.NoObject" values found:
   Invalid Object
   Invalid object

The dupvalues.txt file lists identical values that are assigned to more than one key. These values are potential "global" key strings. For example, the following listing identifies two keys to which the same value — "Move Selected Items Up" — is assigned.

"Move Selected Items Up" keys found: 
   server.WcmMultiValueSelectXSL.MoveSelectedItemsUp
   server.WorkflowExpressionModuleXSL.MoveSelectedItemsUp

The allvalues.txt file is a comprehensive list of all of the UI and exception strings of the source parsed by ResourceParser.

Loading Resource Bundles at Runtime

If you generate custom resource bundles, you must explicitly load them. You can do this with your own static initializer that loads your custom bundles.

There are different ways to create a static initializer. If you are using the out-of-the-box ConfigurableController, you can subclass it and override the initializeStaticClasses() method. Alternatively, you can configure the out-of-the-box ConfigurableController with the "staticInitializer" option in p8controller.xml. This option specifies a static initializer class that can supplement or supplant the WcmController.initializeStaticClasses() method.

The following code fragment shows the use of a static initializer class for which ConfigurableController would be configured to call. The bundlePath variable is set to the location of the custom resource bundles, and the getBundle method returns the custom bundles as ResourceBundle objects. The addXXXBundleToPath methods load the resource bundles for WcmString.class and for WcmException.class.

public class StaticInit extends ConfigurableController implements StaticInitializerInterface
{
   ...

   public void initializeStaticClasses(WcmController c) throws Exception
   {
      super.initializeStaticClasses();
      String localPath = (String)dataStore.getValue(BASE_LOCALPATH_KEY);
      String bundlePath = localPath + "WEB-INF" + File.separator + "resources";
      ResourceBundle bundle = WcmStringResources.getBundle(bundlePath,
         "CustomStringConfiguration");
      WcmStringResources.addStringBundleToPath(bundle);
      bundle = WcmStringResources.getBundle(bundlePath,
         "CustomExceptionConfiguration");
      WcmStringResources.addExceptionBundleToPath(bundle); 
   }
   ...
}

If WcmStringResources cannot find the specified property list file, then WcmString and WcmException will use the English string in the constructor, for example:

new WcmString("custom.customModule.helpLink", "Help");

Translating Resource Bundles

If you translate property resource bundles:

XLIFF Files

XLIFF files (XML Localization Interchange File Format) are introduced in FileNet P8 4.0 to support displaying user-authored names in Workplace and other Toolkit-based applications. This file format is the industry-accepted XML specification standard for the exchange of locale-specific data. XLIFF files augment existing resource bundle files, which contain static strings, as opposed to real-time, user-authored strings.

A user-authored name string is supplied by the user while defining Process Engine (PE) configuration items and workflow definitions. The name strings are saved to the PE database and later used as keys for looking up locale-specific values of the strings in XLIFF files. In Workplace, user-authored names are employed by rosters, queues, milestones, steps, workflows, and various other fields. The name strings are used as keys into the XLIFF files to provide locale-specific string values for:

The PE Configuration Console is used to export the user-authored name strings to a language-specific XLIFF version 1.1 file.

The custom web application developer is responsible for providing the necessary translations for the user-authored name strings in the XLIFF files for the locales to be supported. The XLIFF files containing the locale-specific string values must be placed in the root path when added to the PEAuthoredNames.jar file. This file is deployed by the user to the web application(s), where it is accessed by the PE API or deployed to the client along with the other jar files. In Workplace, the jar file is deployed to the download and WEB-INF\lib directories.

The PEAuthoredNames.jar file can be created as follows:

  1. Create a staging directory. For example, C:\temp.
  2. Create the destination directory for the XLIFF files. For example, C:\temp\XLIFF.
  3. Copy the translated XLIFF files to the destination directory created in Step 2.
  4. From the staging directory created in Step 1, create the PEAuthoredNames.jar file. For example:
    jar -cvf PEAuthoredNames.jar filenet
  5. Deploy the PEAuthoredNames.jar file to the download and WEB-INF\lib directories.

Workplace exposes the “Preferred Locale” user preference and passes the browser locale to the web application using WcmPlugInModule. At run-time, the application retrieves the browser locale and calls the setLocale() method on the VWSession object (Tasks pages and Step Processors). This causes the corresponding XLIFF file to be loaded (if it has not already been loaded). As the application retrieves information from the PE API objects, the locale-specific (translated) strings are retrieved from the XLIFF files using the user-authored name strings as keys. If a locale-specific string is not available, the user-authored name string is returned.



Feedback

© Copyright IBM Corporation 2011.
This information center is powered by Eclipse technology. (http://www.eclipse.org)