Tuesday, May 14, 2013

Easier localization

Image by Tobias Mikkelsen
Form Builder and Form Runner support internationalization out of the box. Concretely this means that you can create a form and localize resources such as control labels, hints, and selection lists into multiple languages.

Internally, this is implemented in Form Runner with:
  • A special XForms instance, fr-form-resources, which holds an XML document with the resources in one or more languages.
  • Logic to pick the current language based on a number of factors (such as whether a specific language was requested with a URL parameter, or was already stored in the session, or was selected by the user).
  • XForms logic which points to the current resources according to the current language and makes them available to all controls via an XForms variable called $form-resources.
One issue with this approach is that the logic must be duplicated, in particular within XBL components (including section templates).

So in Orbeon Forms 4.2, we introduce a new function called simply r (for "resource"), which you typically call with xxf:r('resource.name'). The function name is short as it might be used very often!

This function removes the need for the boilerplate logic in each form and XBL component (the resources instance, of course, remains). Here is a simple example:
<xf:item>
    <xf:label value="xxf:r('year')"/>
    <xf:value/>
</xf:item>
With Orbeon Forms 4.2, this function is only used by a few XBL components. In the future we plan to update all XBL components as well as Form Runner and Form Builder to use this mechanism.

No comments:

Post a Comment