Add language support using Sitemagic CMS

Sitemagic CMS features a simple mechanism for adding localization (language support) to Sitemagic CMS. This is done using XML translation files and the SMLanguageHandler class.
By default Sitemagic CMS comes with support for English and Danish. Adding e.g. Swedish or German is quite simple as the following example demonstrates.
First of all you should know that an English translation file is mandatory. If a given extension does not support the language selected in Sitemagic CMS, it will revert to the English translation file. The language files are stored in a sub folder of an extension folder called Languages. So adding language support for German and English requires the following files:
  • MyExtension/Languages/en.xml (mandatory when using the SMLanguageHandler class)
  • MyExtension/Languages/de.xml
Language files are named according to ISO-639-1 (hence de.xml for German and en.xml for English).
The two language files above could look something like this:
en.xml
<?xml version="1.0" encoding="ISO-8859-1"?>
<entries>
    <entry key="Title" value="Products" />
    <entry key="Description" value="Our great products" />
</entries>

de.xml
<?xml version="1.0" encoding="ISO-8859-1"?>
<entries>
    <entry key="Title" value="Produkte" />
    <entry key="Description" value="Unsere großartige Produkte" />
</entries>
Make sure to save translation files using ISO-8859-1 character encoding as explained in best practices.
Now, to read and use these translations in an extension, simply use the following code:
$language = new SMLanguageHandler($this->context->GetExtensionName());

$title = $language->GetTranslation("Title");
$description = $language->GetTranslation("Description");
From which file translates are being read depends on the language set in Settings. But if an alternative language was selected when the website owner logged in, this language will be used instead.
By default Sitemagic CMS is configured with support for English (en), Danish (da), and German (de). To make your translations available to Sitemagic CMS, a small change must be made to config.xml.php in the root of your Sitemagic CMS installation.
config.xml.php
<?php exit(); ?>
<?xml version="1.0" encoding="ISO-8859-1"?>
<entries>
    ...
    <entry key="Languages" value="en;da;de;aa;bb;cc" />
    ...
</entries>
In the example above we added three fake languages (aa, bb, and cc) to the Languages entry in config.xml.php, which will make them available from both Settings and when logging in. Remember that selecting a language that is not supported by Sitemagic CMS will cause most of the user interface to use English - only the extensions supporting the language selected will be translated.