How to internationalize W4 Toolkit applications

Many applications have to support different user interface languages. Therefore all texts (labels, tooltips etc.) should not be hard-wired into the UI code, but instead either be read from a database or from resource files, e.g. a simple property or XML file. W4Toolkits session preload mechanism and the W4T Eclipse code generation involve a encapsulation of the standard API for String internationalization. This text describes the functionality of the built-in I18n support of W4Toolkit and how to use it within W4T Eclipse.

A Resolution Mechanism

To support W4 Toolkits session preload mechanism the library has a build in functionality to resolve internationalized strings during the Render Phase of a WebForm request. For more information about LifeCyle Management of a request in W4 Toolkit you may have a look at the whitepaper. To resolve strings (e.g. the value attribute of a WebLabel) the string is replaced with an URI like locator:


  property://<propertyKey>@<bundleBaseName>
 
Property files are normally packaged within the the applications archive. If you use the W4T Eclipse deployment wizard, this is done automatically.

To make different languages available for your application, you have to translate each property file of your application to the languages you want to support. Since this relies on the standard I18n support, you may have a look at the naming conventions and the lookup strategies described here.

The default Locale used for resource lookup depends on the browsers language request. This is handled automatically by the library (information about the browser at runtime is available through the Browser object). To override locale used in the resolution use the W4TContext.setLocale(Locale)-method.

Note: The resolution only works with strings representing text elements of gui components. Other strings like html based format specifications (e.g. '100%' for width attributes) are not part of the resolution mechanism. Exceptions to that rule are explicitly noted in the JavaDoc documentation for the respective attributes. An important exception is the characterSet attribute of the WebForm. This facilitates setting a language specific character set if necessary.

Using the String-Edit-Dialog

Internationalization of your W4Toolkit applications is quite easy using the String-Edit-Dialog of W4T Eclipse. You can open this Dialog for every String typed attribute of an W4 Toolkit component displayed in the property view. The dialog contains two tabs. The value tab contains the content text field where you can edit the string value of the selected attribute. The other tab is called I18n and is used to asign the value to an entry in a property file.

Suppose you want to internationalize the value attribute of a WebLabel. Open the String-Edit-Dialog and select the I18n tab.

As you can see the the dialog already provides a proposal for the key (with a class prefix), but there exists no property file in the package yet. Use the 'new' button to open the new file wizard with which you can create your property file (e.g. messages.properties). If your property file is not to be located in the current package you will have to uncheck the according checkbox to see it in the file list. After selection of your property file you can assign the key=value pair to the selected file. Confirm the changes with the OK-button. Your newly created property file looks like this:

  #I18n property file created with W4T Eclipse
  #Mon Oct 27 10:27:00 CET 2003
  MyForm.user_input_1_=user input 1\:
The code generation of W4T Eclipse builds the WebLabels initialise method:
  private void initialiseWlbInput1() throws Exception {
    this.add( wlbInput1, new Position( 2, 2 ) );
    wlbInput1.setName( "wlbInput1" );
    wlbInput1.setValue( "property://MyForm.user_input_1_@example.messages" );
  }
To modify the value of a property file entry you can either change the value directly in the property file, or you open again the String-Edit-Dialog. Changing the value in the content field and confirming the changes by pressing the OK-button will write the changes to the property file. Note: you can not edit the value with the cell editor of the property page, since this value is the URI of the display value and not the value itself.

Once you have created a property file you can add as many entries as you like. You can also use this property file for internationalization in non-W4 Toolkit component classes using the IDE's built-in I18n support.


Copyright (c) 2003 by Innoopract Informationssysteme GmbH. All rights reserved.