Wednesday, March 14, 2012

Multilingual documentation for an Android project with Docbook

Two interesting challenges, while writing the multilingual tutorial for My Expenses:
  1. Use one single input file facilitating translation
  2. Reference interface messages from the project's resource files instead of repeating them literally, in order to assure consistency.
For the first one, I borrowed a stylesheet from DocBook.sml that allows to generate language-specific files from the multilingual document. These can then be further processed into html and pdf with the standard Docbook XSLT.

My solution to the second one, can be found in this customization of the chunking template. Have a look at how the inline.charseq template is overridden. This is the important part:

  <xsl:choose>
  <xsl:when test="normalize-space(.)">
   .....
  </xsl:when>
    <xsl:otherwise>
      <xsl:value-of select="document($resfile)/resources/string[@name = $id]">
    </xsl:value-of></xsl:otherwise>
  </xsl:choose>

When the element has no content, localized string is looked up in the resource file, based on the role attribute of the element, stored earlier in the variable id. Now elements like <guimenuitem role="select_account"/> are rendered with their translated message.

No comments:

Post a Comment