Elxis CMS Forum

Support => Elxis 2008 developers guide => Topic started by: datahell on March 19, 2007, 22:00:41

Title: Multilingual XML with custom language files
Post by: datahell on March 19, 2007, 22:00:41
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) [Select]
<?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;
    }
}
?>


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) [Select]
<?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>
..................

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.
Title: Re: Multilingual XML with custom language files
Post by: Farhad Sakhaei on September 11, 2007, 16:46:10
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
Title: Re: Multilingual XML with custom language files
Post by: datahell on September 11, 2007, 17:58:01
I think you can do this with css
Title: Re: Multilingual XML with custom language files
Post by: Farhad Sakhaei on September 11, 2007, 19:23:22
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 ...  ???
Title: Re: Multilingual XML with custom language files
Post by: datahell on October 03, 2007, 21:12:08
Added dir="ltr" to input type="text" and to select fields on parameter rendering feature (mambots, modules, components, bridges).
Title: Re: Multilingual XML with custom language files
Post by: Farhad Sakhaei on October 04, 2007, 01:01:41
good , very thanx john  :) ;)
but what about some fields that they give persian text ? they should be RTL !
Title: Re: Multilingual XML with custom language files
Post by: datahell on October 04, 2007, 07:51:23
As you understand Elxis can not guess the kind of information a text field contains. If for example it is a URL, a module suffix or your real name. Textareas were left intact in order to be able to write RTL. Text inputs for parameters (only) became always LTR as you more often write there latin text like prefixes and numbers.
Title: Re: Multilingual XML with custom language files
Post by: Farhad Sakhaei on October 04, 2007, 15:06:09
ok john, can i change some of them (textboxes) that they should be RTL ?
for example can i edit the codes , and decide which textbox should be LTR and RTL ?
in elxis 2006 , we cannot change the direction of parameters of modules , mambot , components ...
can i set them by adding a code or not ?
if we can do this , it will be very good , if not , i want that all textboxes leave without any direction property ...
Title: Set text direction for any XML parameter.
Post by: datahell on October 04, 2007, 22:26:44
You know better RTL than me, so your wish now fullfilled. Here is the total RTL solution for XML parameters.
Please use it as a general guide:

A new (optional) node can be placed inside text and textarea (select fields should always be ltr, is this right? ). It's name is dir and can have 2 values: ltr and rtl (lowercase or uppercase, no matter). If the gemini language constant _GEM_RTL has been set to 1 (selected language is an RTL language) then it is triggered an RTL set mechanism.

If dir is set to ltr or dir wont set at all (for compatibility) then the text direction becomes LTR by default for RTL languages.

Example:
<param name="where_id" dir="ltr" type="text" default="" label="CX_UCD_CSRSID" description="CX_UCD_CSRSIDD" />
or
<param name="where_id" type="text" default="" label="CX_UCD_CSRSID" description="CX_UCD_CSRSIDD" />

Both of the above for RTL languages will generate:
<input type="text" dir="ltr" name="params[where_id]" value="2,3,4,5" class="inputbox" size="" />
for non-RTL:
<input type="text" name="params[where_id]" value="2,3,4,5" class="inputbox" size="" />

If dir is set to rtl then the text direction becomes RTL for RTL languages.

Example:
<param name="where_id" dir="rtl" type="text" default="" label="CX_UCD_CSRSID" description="CX_UCD_CSRSIDD" />
The above will generate for RTL languages:
<input type="text" dir="rtl" name="params[where_id]" value="2,3,4,5" class="inputbox" size="" />

and for non-RTL (rtl node is being ignored):

<input type="text" name="params[where_id]" value="2,3,4,5" class="inputbox" size="" />

I think it is the best solution possible and I hope friends from Iran, Israel etc will be very happy for this.

Developers should use the dir="rtl" node in XML parameters for text and textarea fields that needed to be displayed in RTL for RTL languages. (LTR languages are not affected)

EDIT: For compatibility reasons I reversed default settings. The post was updated!
Title: Re: Multilingual XML with custom language files
Post by: Farhad Sakhaei on October 05, 2007, 20:17:33
john , select fields depend on type of its content may be LTR or RTL , for example for a select language it should be LTR because the options are latin words , but for some select boxes , that they have values that they are in language files and they translated , it should be a RTL select box , like : align , positions , sections , categories select boxes and many another ...
however most of TEXTAREAs are RTL in Right to Left languages , but if it contains a code , it should be LTR too ...

i think it is better to insert a direction property for all SELECT , INPUT (Text fields) , TEXTAREA tags , and it is better to don't set any direction value for them , they can be LTR in LTR pages and RTL in RTL pages , so if we want to set any of them to LTR , we can insert a LTR direction value for compatibility in RTL pages to set that fields to LTR and leave another fields to default ...

this is a sample:
we have 5 fileds below :
1- a name text box
2- an email text box
3- a language select box
4- an author name text box
5- an alias for author text box

if we leave dir property to default (not to set any value) they will be :
in a LTR page all of them will be LTR , because we input all textbox values in latin ...
in a RTL page all of them will be RTL , because for default direction , so fields 1,4,5 are in true direction now but fields 2,3 are not in true direction because for latin characters and words , these tags can be set to LTR by adding a dir="ltr" property ...

i think , another solution to set default value for all properties (set LTR or not set any values) is gathering a statistic from all modules and components and mambots , we can count the number of parameters , count of RTL fields and LTR fields , if the number of LTR fields are more than RTLs or not , so we can decide that they will be set to LTR or not to set any value ...
i will write here a statistics about numbers of these fields !!!
Title: Re: Multilingual XML with custom language files
Post by: datahell on October 05, 2007, 21:56:20
Ok the "dir" flag will also be added to SELECT fields. For compatibility I think it is much better to display by default everything in LTR even for RTL languages. Why? Because the existing components, modules, mambots etc do not have the dir flag so they will display text in RTL direction by default. But the most text fields (XML parameters) contain latin characters and numbers (at least 80% of them) so it will be much better to be displayed in LTR by default.

My proposal:
Everything set to LTR by default if no dir flag is set. (SELECT, INPUT, TEXTAREA)

If you wish we can make specific default settings for each type of field (e.g. TEXTAREA by default RTL, the others LTR) but this will confuse developers, so I dont think this is a good choice. We need a general guide.

You write in RTL so you decide if you wish RTL or LTR direction by default. Also I need a list of XML parameters for Elxis core (mambots, modules, components, bridges, menus) that you want to be displayed in RTL inorder to update Elxis XML files and be ready for the release.
Title: Re: Multilingual XML with custom language files
Post by: Farhad Sakhaei on October 05, 2007, 23:37:02
ok, is it better that i tell them to you , when you give us betta version ? because i think ELXIS 2008 has very changes with 2006