Translation in XSLT
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 |
dict:translate
The dict:translate API is a direct call from XSLT to the Plex GetTranslation function in the Security and/or PlexXMLF Model. If you haven't modified it, this function takes the translation form the LookUp-Table that is defined in the Security-Model.
You are able to call it with 2 parameter:
- SessionID: Internal SessionID. Used to fetch the language of the current user.
- LookUp-Key: Key that is used to fetch the translation in the LookUp-Table. It is also the initial translation if the record can't be found.
<xsl:value-of select="dict:translate($vSessionID,'Satzhistorie anzeigen')"/>
Or with 6 parameter.
- SessionID: Internal SessionID. Used to fetch the language of the current user.
- LookUp-Key: Key that is used to fetch the translation in the LookUp-Table.
- First-Language: Initial translation language if the record can't be found.
- First-Translation: Initial translation if the record can't be found.
- Second-Language: Initial translation language if the record can't be found.
- Second-Translation: Initial translation if the record can't be found.
<xsl:value-of select="dict:translate($vSessionID,'Anmelden','de','Anmelden','en','Login')"/>
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> ...
DEPRECATED: 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.