0 users online. Create an account or sign in to join them.Users

Author:
mprofitl
Version:
1.0
Release Date:
6 Dec 2016
Category:
Interface

Description

This utility adds a language switch for all languages of the site (when using multilanguage the right way).

It takes its information from the navigation and fl-languages datasources.

Parameters are the most difficult part to implement as they come in one language only. It is therefore necessary to look up a parameter's translation in a datasource. For example: If your page is products and the parameter is $prodctgroup, you will need a datasource that lists all product groups in all languages. The xml shows an example. For sites with many parameters on different pages it might be useful to apply a template, placed on each page, from within the utility.

XSLT

View Raw
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">



<xsl:template match="fl-languages">
    <ul class="nav__language">
        <xsl:apply-templates select="supported-languages/item" />
    </ul>
</xsl:template>

<xsl:template match="supported-languages/item">
    <li class="nav__language__item">
        <xsl:if test="/data/fl-languages/current-language/@handle = current()/@handle">
            <xsl:attribute name="class">nav__language__item  nav__language__item--active</xsl:attribute>
        </xsl:if>
        <a class="nav__language__item__link">
            <xsl:attribute name="href"><xsl:value-of select="concat($root,'/',@handle)" />
                <xsl:apply-templates select="/data/navigation" mode="language">
                    <xsl:with-param name="lang" select="@handle" />
                </xsl:apply-templates>
                <!-- PARAMETERS START -->
                <xsl:value-of select="concat('/', /data/DATASOURCENAME/entry/FIELD/item[@lang = current()/@handle]/@handle)" />
                <!-- PARAMETERS END -->
            </xsl:attribute>
            <xsl:value-of select="@handle" />
        </a>
    </li>
</xsl:template>

<xsl:template match="navigation" mode="language">
    <xsl:param name="lang" select="''" />
	<xsl:apply-templates select="page" mode="language">
		<xsl:with-param name="lang" select="$lang" />
	</xsl:apply-templates>
</xsl:template>

<xsl:template match="page" mode="language">
	<xsl:param name="lang" select="''" />
	<xsl:if test="descendant-or-self::node()[@id = $current-page-id]">
		/<xsl:value-of select="item[@lang = $lang]/@handle" />
	</xsl:if>
	<xsl:if test="descendant-or-self::node()[@id = $current-page-id]">
		<xsl:apply-templates select="page" mode="language">
			<xsl:with-param name="lang" select="$lang" />
		</xsl:apply-templates>
	</xsl:if>
</xsl:template>

</xsl:stylesheet>

Discuss this XSLT Utility

Symphony • Open Source XSLT CMS

Server Requirements

  • PHP 5.3-5.6 or 7.0-7.1
  • PHP's LibXML module, with the XSLT extension enabled (--with-xsl)
  • MySQL 5.5 or above
  • An Apache or Litespeed webserver
  • Apache's mod_rewrite module or equivalent

Compatible Hosts

Sign in

Login details