<?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl=http://www.w3.org/1999/XSL/Transform xmlns:msxml="urn:schemas-microsoft-com:xslt" xmlns:umbraco.library="urn:umbraco.library" xmlns:kv_trans ="urn:kv_trans" exclude-result-prefixes="msxml umbraco.library kv_trans"> <xsl:output method="xml" omit-xml-declaration="yes"/> <xsl:param name="initlang">en</xsl:param> <xsl:variable name="dlang"> <xsl:choose> <xsl:when test="umbraco.library:RequestQueryString('lang') != '' "> <xsl:value-of select="umbraco.library:RequestQueryString('lang')" /> </xsl:when> <xsl:when test="umbraco.library:Session('lang') != ''"> <xsl:value-of select="umbraco.library:Session('lang')" /> </xsl:when> <xsl:otherwise> <xsl:value-of select="$initlang" /> </xsl:otherwise> </xsl:choose> </xsl:variable> <xsl:variable name="flang"> <xsl:if test="$dlang != '' and $dlang != $initlang "> <xsl:value-of select="concat('_',$dlang)" /> </xsl:if> </xsl:variable> <xsl:template name="setlang"> <xsl:value-of select="umbraco.library:setSession('lang',$dlang) " /> </xsl:template> </xsl:stylesheet>
<xsl:template match="/"> <xsl:call-template name="setlang" /> ... </xsl:template>
<xsl:include href="../xslt/lang_lib.xslt" />
<xsl:value-of select="$currentPage/data[@alias = 'ALIASNAME']" />
<xsl:value-of select="$currentPage/data[@alias = concat('ALIASNAME',$flang)]" />
<xsl:value-of ...
using System; using System.Collections.Generic; using System.Text; using System.Xml; using System.Web; using System.Xml.XPath; using umbraco.cms.businesslogic; using umbraco.cms.businesslogic.language; // Adds dictionary lookup as an extension for XSLT files. /TORK 2008.04.30 namespace kraftvaerk.umbraco { public class Translations { /// <summary> /// Look up a translated string in the Umbraco dictionary using the provided key and language code /// Returns the translated string if found and not empty. Else, it returns the key and the language /// surrounded with "*" for easy detection and correction. /// </summary> /// <param name="key">The key by which the dictionary entry was made</param> /// <param name="language">The desired language code- as it appears on the dictionary tabs</param> /// <returns>The translated string, if found and not empty. returns> public static string translate(string key, String language) { int langid = 1; if (language.Length != 5) language = "en-US"; // hardcoded default language. // Reimplement as desired. Language lang = Language.GetByCultureCode(language); langid = lang.id; string trans = GetDictItemByLang(key, langid); if (trans.Length > 0) return trans; return ("*" + key + "(" + language + ")" + "*"); } /// <summary> /// Lookup the key in the Dictionary, then get the value for the correct language-id /// </summary> /// <param name="key">The key by which the dictionary entry was made</param> /// <param name="languageid">The id of the choosen language</param> /// <returns>The translated string or the empty string. returns> private static string GetDictItemByLang(string key, int languageid) { try { return new Dictionary.DictionaryItem(key).Value(languageid); } catch { return string.Empty; } } } }
<?xml version="1.0" encoding="utf-8" ?> <XsltExtensions> <ext assembly="/bin/kv_umb_lib" type="kraftvaerk.umbraco.Translations" alias="kv_trans" /> </XsltExtensions>
<xsl:stylesheet version="1.0" xmlns:xsl=http://www.w3.org/1999/XSL/Transform xmlns:msxml="urn:schemas-microsoft-com:xslt" xmlns:umbraco.library="urn:umbraco.library" xmlns:kv_trans ="urn:kv_trans" exclude-result-prefixes="msxml umbraco.library kv_trans"> ...
kv_trans
<xsl:value-of select="kv_trans:translate('KEY',string($dlang))" />
<div class="languageselector"> <a href="?lang=en">ENGLISH</a> | <a href="?lang=sv">SVENSKA</a> | <a href="?lang=da">DANSK</a> </div>