Front-end locale
Localizes the front-end in a familiar way! (when you have seen the Symphony core code)
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>