Language Localization

One of the main advantages of separating out the Content from the View is that it is easy to implement multiple languages while sharing the same look-and-feel. You may use the xml:lang to label which languages tags are in.

The preferred language of the user is determined as follows.

Applying to Content: HTML::Template::XPath

HTML::Template::XPath supports language localization through the use of the xml:lang attribute. In PageKit 1.01 and above, the algorithm for selecting the node(s) for the selected languages is as follows:

  • First it attempts to use the XPath function lang to return the node or the set of nodes whose xml:lang attribute(s) are the same as the preferred language. If the node has no xml:lang, then the value of the xml:lang attribute on the nearest ancestor is used. If the node and the its ancestors have no xml:lang attribute, then the default_lang language is used.

  • If no nodes are found in the preferred language, then it returns the node(s) which are in the default_lang language.

The algorithm in PageKit 1.00 is slightly different from the above, but follows the same basic idea.

Applying to Content: XSLT

As of release 1.00 there is no support for Language Localization using XSLT. However I plan to offer support in one of the two following ways:

  • Different source XML files, foo.en,,, and so on.

  • PageKit will set the <xsl:param name="pkit_lang"> tag in the XSLT stylesheet.

Comments, suggestions, and patches welcome!

Applying to Model

To use the language settings from the Model, simply use the pkit_lang method.

This can be useful for selecting content from the database based on language.

Character set translation

By default, PageKit attempts to output using default_output_charset. PageKit will attempt to translate the PageKit Templates and output passed to output_convert from default_input_charset to default_output_charset.

Note: This also applies also to the message catalog if any. So write your message catalog files in default_input_charset.

PageKit attempts to translate the output to a character set that is specified in the Accept-Charset header. If this is not possible, PageKit delivers the page in the default_output_charset.