Support > Elxis 2008 developers guide

Multilingual XML with custom language files

(1/3) > >>

datahell:
Elxis 2008 supports custom language files for translating XML parameter files. This feature concerns any sub-application that uses XML files (modules, components, mambots). As you most probably know 2006.x versions 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!

Class xmlLanguage started 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'.

Function get() was updated to support inputs from custom language files.
The new get() function:


--- Code: (php) ---<?php 
function get($a) {
    if ( is_numeric($a) ) { return $a; }
    $pref = strtoupper(substr($a,0,3));
    if ($pref == &#39;AX_&#39;) {
        return $this->$a;
    } elseif (($pref == &#39;CX_&#39;) && defined($a)) {
        return constant($a);
    } else {
        return $a;
    }
}
?>

--- End code ---

As you see you can now insert as input a constant which name starts from 'CX_'

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

example 3


--- Code: (XML) ---<?xml version="1.0"?>
<mosinstall type="module" version="2008">
<name>Multi Search</name>
................
<authorUrl>www.elxis.org</authorUrl>
<cxlangdir>/modules/mod_multisearch/language</cxlangdir>
<version>1.0</version>
<description>Display multiple search forms. Created by Ioannis Sannos.</description>
<files>
..................

--- End code ---

Your language files are located inside the folder /modules/mod_multisearch/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_'.

example 4
define('CX_START', 'Start');
define('CX_HOWRY', 'How are you?');


Parameters render function in Core/elxisxml.php file updated to support the new-implemented feature.

Farhad Sakhaei:
thanx ioannis , is there any feature to set a direction property into a xml parameter?
becasue i use persian language and some text box should be LTR and some of them should be RTL , for example for a URL text box , it should be LTR , but for a name text box it should be RTL to enter a right to left sentence or word

datahell:
I think you can do this with css

Farhad Sakhaei:
yes but it will need many css classes , because for example we have about 50 textboxes in whole administration that they need RTL property and we have 20 textboxes that they should be LTR ... by default in our RTL page , textboxes are RTL because HTML Direction is RTL ...
now we should add 20 classes to control textboxes with LTR direction , and so some of them are in future  components and other addons...
i think this is not a good idea ...  ???

datahell:
Added dir="ltr" to input type="text" and to select fields on parameter rendering feature (mambots, modules, components, bridges).

Navigation

[0] Message Index

[#] Next page

Go to full version