... Elxis version 2009.3 codename Aphrodite is out, download it from Elxis Download Center (EDC) ...

Multilingual XML parameters

From Elxis Official Documentation

Jump to: navigation, search

Elxis 2008+ supports custom language files for providing multilingualism in XML parameters. This feature concerns any sub-application that uses XML files such as modules, components and bots. As you most probably know, elxis 2006.x generation had multilingual support for XML files using the standard XML files from the administration language package. But there was no way to add multilingual strings to a custom module or component. Now you can do that!


Elxis 2006.x

All standard XML language files, located at Elxis administration language folder, contain a PHP class named xmlLanguage which starts with the function get(). get() usage is pretty simply. As input gets a string from the XML file and returns the translated string if the strings starts with "AX_" or the untranslated string if nothing found.

//example 1
$xmlLanguage->get('test');
//will return: test


//example 2
$xmlLanguage->get('AX_MENUIMGL');
/* 
will return: the translated string of the variable $AX_MENUIMGL, 
which for the english language is: "Menu Image".
*/


Elxis 2008.x/2009.x

Function get() supports inputs from custom language files. Here is the get() function for Elxis 2008.0+:

function get($a) {
     if ( is_numeric($a) ) { return $a; }
     $pref = strtoupper(substr($a,0,3));
     if ($pref == 'AX_') {
         return $this->$a;
     } elseif (($pref == 'CX_') && defined($a)) {
         return constant($a);
     } else {
         return $a;
     }
}

As you see you can now insert as input a constant which name starts from CX_ (Custom Xml language).

How you declare your language files? Inside the xml file add a tag named cxlangdir and write inside it the relative path to the folder that are located your custom language files.

<?xml version="1.0"?>
    <mosinstall type="module" version="2009">
    <name>module name</name>
    <authorUrl>www.elxis.org</authorUrl>
    <cxlangdir>/modules/mod_mymodule/language</cxlangdir>
    <version>1.0</version>
    <description>module description</description>
    <files>

Your language files are located inside the folder /modules/mod_mymodule/language. Of course you can set this to any folder. The path is the relative path from the Elxis root folder to that folder that contains your language files. Your language files names should follow the Elxis standards (english.php, italian.php, greek.php, german.php etc).

Language strings inside that files must be declared as PHP constants starting with "CX_".

//on english.php
define('CX_START', 'Start');
define('CX_HOWRY', 'How are you?');
 
//on greek.php
define('CX_START', 'Έναρξη');
define('CX_HOWRY', 'Πως είσαι;');


Read also: XML Installation files for modules

Personal tools