Author:
Zimmen
Version:
1.1
Release Date:
11 Nov 2010
Category:
Output

Description

Updated version: change of heart thanks to froded. Now uses external xml file, not a datasource!

Localizes the front-end (buttons, static headings, etc etc) in a way that is very familiar when you have ever seen the Symphony Core source.

Use this utility in conjunction with a Locale-strings.xml XML file in the format:

<?xml version="1.0" encoding="UTF-8"?>
<locales>
      <item>
        <key>[default language senctence]</key>
        <[language code]>[translated sentence]</[language code]>
      </item>
    </locales>

Example (default language is english):

<?xml version="1.0" encoding="UTF-8"?>
    <locales>
      <item>
        <key>This is a nice sentence!</key>
        <nl>Dit is een mooie zin!</nl>
      </item>
      <item>
        <key>The cat crawls the curls of the stairs</key>
        <nl>De kat krabt de krullen van de trap</nl>
      </item>
    </locales>

Usage: Save the Locale-strings.xml file in the same folder as the utility.

Add zmn namespace to your stylesheets

<xsl:stylesheet version="1.0"  xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:zmn="http://zimmen.com/functions">

Import the utility in your page (or master utility)

<xsl:import href="../utilities/Locale.xsl" />

In your templates:

<h1><xsl:value-of select="zmn:__('This is a nice sentence!','nl')" />

Output:

Dit is een mooie zin!

XSLT

View Raw
<?xml version="1.0" encoding="UTF-8"?>

<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
xmlns:zmn="http://zimmen.com/functions"
xmlns:func="http://exslt.org/functions"
extension-element-prefixes="func">

<!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

  Front-end locale.
  Localizes the front-end (buttons, static headings, etc etc) in a way that is 
  familiar when you have ever seen the Symphony Core source.
  
  version:  1.00
  author:   Simon de Turck
  email:    simon@zimmen.com
  
  
  Use this utility in conjunction with a Locale-strings.xml XML file in the format:
  
  <?xml version="1.0" encoding="UTF-8"?>
  <locales>
    <item>
      <key>[default language senctence]</key>
      <[language code]>[translated sentence]</[language code]>
    </item>
  </locales>
  
  Example (default language is english):
  	<?xml version="1.0" encoding="UTF-8"?>
    <locales>
    <item>
      <key>This is a nice sentence!</key>
      <nl>Dit is een mooie zin!</nl>
    </item>
    <item>
      <key>The cat crawls the curls of the stairs</key>
      <nl>De kat krabt de krullen van de trap</nl>
    </item>
  </locales>
  
  
  Usage:
        Save the XML file in the same folder as the utility.
        
        Add zmn namespace to your stylesheets
        <xsl:stylesheet version="1.0" 
          xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
          xmlns:zmn="http://zimmen.com/functions">
        
        Import the utility in your page (or master utility)
  
        In your templates:
        <h1><xsl:value-of select="zmn:__('This is a nice sentence!','nl')" />
        
        Output:
        <h1>Dit is een mooie zin!</h1>
  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
  
  <xsl:param name="strings" select="document('Locale-strings.xml')" />
  
  <func:function name="zmn:__">
    <xsl:param name="in" />
    <xsl:param name="lang" select="''" />
 
    <func:result>
      <xsl:choose>
        <xsl:when test="count($strings/locales/item[key/text()=$in]/*[local-name()=$lang]) > 0">
          <xsl:value-of select="$strings/locales/item[key/text()=$in]/*[local-name()=$lang]" />
        </xsl:when>
        <xsl:otherwise>
          <xsl:value-of select="$in" />
        </xsl:otherwise>
      </xsl:choose>
    </func:result>
    
  </func:function>
</xsl:stylesheet>

Discuss this XSLT Utility

Symphony • Open Source XSLT CMS

Server Requirements

  • PHP 5.3-5.6 or 7.0-7.3
  • 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