Internationalization (i18n) support means that applications have the ability to display itself in multiple languages or locales. This doesn't necessarily mean that the application supports inputting data in multiple languages or translating stored data into another language for display. WW makes it easy for you to provide i18n support for GUI display by utilizing ResourceBundles.

Resource bundles are property files with special names. Lets take for example a WW i18n application Webshop app. This application provides i18n support for English, French, Swedish, and German languages by providing 4 resource bundles located under webwork/action/test/i18n. These files are Shop.properties, Shop_de.properties, Shop_fr.properties, and Shop_sv.properties. These files correspond to a base class property file, a German property file, a French property file, and a Swedish property file. But, where is the English property file? We will soon see.

The resource bundles are named after a base action for this application named Shop. This action extends ActionSupport which provides methods to load resource bundles and return i18n text. It is quite common for developers to extend their actions from this base class. Extending this class allows you to do the following if one of your actions is on the ValueStack.

Use ActionSupport's getText() method with user as the key to find the appropriate i18n text.

<ui:textfield label="text('user_name')" name="'user'"/>

The non UI tag text will retrieve appropriate text from your resource bundle. In the next example, it is used to retrieve i18n text for the name value.

<webwork:text name="'cd.quantityLabel'"/>

In addition, you can use text to perform message formats for more sophisticated i18n needs. In the next example, text will retrieve i18n text for name value price which will return {0,number,currency} - see MessageFormat for more details. This pattern will be used to format the value in value0. For this example, this means our currency will be displayed appropriately - $ for Dollar, etc.

<webwork:text name="'price'" value0="totalPrice"/>
</ww:property>

Now, back to the resource bundles. Remember earlier, that we said we did not provide an English resource bundle. The reason is that our base resource bundle Shop.properties is serving as our English resource bundle. For the other language bundles, we wrote over keys that should be language specific. With this setup, WW's ActionSupport class will use the following algorithm to retrieve i18n text.

  1. Find appropriate resource bundle for the specific action and locale that has its getText() called.
  2. If the resource bundle is not found, start up the inheritance tree looking for it.
  3. If the bundle is found, search for the key first in a locale specific bundle otherwise use the base bundle.

WW provides you another custom tag for your i18n needs. This tag is named i18n and it allows you to place a resource bundle on the ValueStack for use inside its tag's body. This allows you to easily mix locales within a page.