Translation in XSLT
From Plex-XML
As you can see in the examples below there are two ways to translate constants in Plex-XML XSLT's. Both ways have almost no performance impact because they use the application cache/are compiled in XSLT.
We prefer translation via database dictionary with an extra messages.xslt because it is the most flexible way.
Contents |
Example
Translation via database dictionary
With extra messages.xslt
<?xml version="1.0" encoding="utf-8"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" xmlns:dict="http://xml.apache.org/xalan/java/de.allabout.basics.LookUpWrapper" exclude-result-prefixes="dict"> <xsl:variable name="sessionID"><xsl:value-of select="/responses/session-attribute[@name='SessionID']/@value"/></xsl:variable> <xsl:variable name="vFoo-TranslatedTitle"><xsl:value-of select="dict:translate($sessionID,'Document')"/></xsl:variable> ... </xsl:stylesheet>
<?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:import href="/WEB-INF/resources/common/DictionarySimpleDialog.xslt"/> <xsl:import href="/WEB-INF/resources/foo/locale/messages.xslt"/> <!-- Translated Title Extension --> <xsl:template name="titleExtension"> <xsl:value-of select="$vFoo-TranslatedTitle"/> </xsl:template> ...
With call-template in your XSLT
<?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:import href="/WEB-INF/resources/common/DictionarySimpleDialog.xslt"/> <xsl:import href="/WEB-INF/resources/common/include/translate.xslt"/> <!-- Translated Title Extension --> <xsl:template name="titleExtension"> <xsl:call-template name="translate"><xsl:with-param name="value">Document</xsl:with-param></xsl:call-template> </xsl:template> ...
Hard-Core in your XSLT
<?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" xmlns:dict="http://xml.apache.org/xalan/java/de.allabout.basics.LookUpWrapper" exclude-result-prefixes="dict"> <xsl:import href="/WEB-INF/resources/common/DictionarySimpleDialog.xslt"/> <!-- Fetch the translation form the database/servlet cache --> <xsl:variable name="sessionID"><xsl:value-of select="/responses/session-attribute[@name='SessionID']/@value"/></xsl:variable> <xsl:variable name="t_Foo-TranslatedTitle"><xsl:value-of select="dict:translate($sessionID,'Document')"/></xsl:variable> <!-- Translated Title Extension --> <xsl:template name="titleExtension"> <xsl:value-of select="$vFoo-TranslatedTitle"/> </xsl:template> ...
Translation via predefined variables in a message-(0).xslt
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:import href="/WEB-INF/resources/common/DictionarySimpleDialog.xslt"/>
<!-- Include the xslt with predefined translated variables -->
<xsl:include href="/WEB-INF/resources/locale/messages-{0}.xslt"/>
<!-- Translated Title Extension -->
<xsl:template name="titleExtension">
<xsl:value-of select="$vFoo-TranslatedTitle"/>
</xsl:template>
...
Be sure to have the localised="true" attribute set in the reaction of the web request. See Web-Requests#.3Creaction.3E for more information about reactions.

