This class uses two levels XML files to translate words,sentences, etc.
It can load one or more translation files at one time.
You can change the default $lang_folder and the default $locale to whatever you need in the class, but they are only used in the get_commun() function, wich is optionnal.
A function i18N_T() is provided to ease the use of the class.
In my case, the structure is :
module
->langages
->fr_FR.UTF-8
->XML file(s)
->en_GB.UTF-8
->XML file(s)
The two XML structures are :
<?xml version="1.0" encoding="UTF-8"?>
<dictionnaire>
<module type="commun">
<couple>
<source>Original word OR sentence</source>
<cible>Translated word OR sentence</cible>
</couple>
</modules>
</dictionnaire>
and
<?xml version="1.0" encoding="UTF-8"?>
<dictionnaire>
<module type="commun">
<couple>
<source>Publier, gérer et lire des fanfics, des histoires originales, des poèmes<br />et autres textes en ligne</source>
<cible>
<couple>
<source type="==1">Il y a %d objet.</source>
<cible>There is %d object.</cible>
</couple>
<couple>
<source type=">1">Il y a %d objets.</source>
<cible>There are %s objects.</cible>
</couple>
</cible>
</couple>
</modules>
</dictionnaire>
Of course, you can mixe them.
The name of the module can be empty. It has no importance in this version, but could have in a further one.
Of course, you can have several modules and several couples in a dictionary.
How to call a dictionary (case french to english) :
include 'class.dictionnaires.php';
$dictionnaire = new dictionnaire($_SESSION['locale']);
$dictionnaire->get_fichiers(array(__DIR__.'/langages/'.$_SESSION['locale'].'/commun.xml'));
How to use it :
print i18N_T("Un objet");
-> prints : An object
Otherwise prints "Un objet" if there is no translation.
You can use more than one dictionary at a time :
include 'class.dictionnaires.php';
$dictionnaire1 = new dictionnaire($_SESSION['locale']);
$dictionnaire2 = new dictionnaire('en_US.UTF-8');
print i18N_T("Consulter tous les articles",null,$dictionnaire1);
You can use comparison for plural :
printf("%d %s",7,i18N_T("nbevenements",'>0'));
|