Localizing Generated Text

The built-in XSLT modules provide a simple and extensible mechanism for managing translations of generated text.

Gentext translation is implemented using a simple XSLT function called {http://www.titaniasoftware.com/namespace/puck-saxfilter-dita}getString() (the namespace is commonly mapped to the prefix p, so p:getString()). This function takes the English string as a parameter and returns the translated string. The default Titania Delivery portal theme implements this function to load strings from XML dictionaries stored in the portal theme itself under the xsl/i18n folder.

String Lookup Strategy

The default portal theme uses the following algorithm to determine the effective language to use.

  1. If the root element of the document carries an @xml:lang attribute, that value is used. You can disable this behavior by specifying the parameter docLangOverrides=no to the transformation.
  2. If there is no @xml:lang or the docLangOverrides=no is used, the $defaultLang parameter is used. The default value for this parameter is en.

You can override this behavior, or the entire translation scheme itself, by modifying the /xsl/i18n/strings.xsl module in the portal theme.

The default p:getString() implementation follows the following algorithm to look up a string.

  1. Look for an XML document matching the current language. If it exists, look up the string in that document. If found, return.
  2. If the current language is regionalized - that is, contains an underscore or dash (like 'en-US' or 'fr_FR'), strip off the suffix and look for a document matching only the language code (so 'en-GB' would fall back to 'en'). Start over at step one with the truncated language code.
  3. If the current language is different from the $defaultLang parameter (because of @xml:lang), start over at step one with $defaultLang.
  4. Otherwise, simply return the input parameter as the string to use.

Adding or Modifying Translated Generated Text Strings

To add new strings, simply modify the XML documents in the /xsl/i18n folder of your theme. These documents use an extremely simple format:

<strings>
  <string key="englishString">Translation</string>
  <!-- Other Strings -->
</strings>

Modify these documents to update the strings used in generated text. To pull in a new string, simply use the p:getString() function from your XSLT files. For example:

<xsl:value-of select="p:getString('My Custom Gentext')"/>

Adding New Languages and Language Variants

To add new languages to the generated text system, simply create a new string library file named for the locale and add it to the /xsl/i18n folder.

You can also add new language variants, such as en_GB or fr_CA by adding appropriately-named XML files. If a string is missing from a regionalized document, the translation system will fall back to the unlocalized library. For example, if a string is missing from fr_CA.xml, the system will look for it in fr.xml.