PHP Classes

PHP i18N Library: Translate application texts loaded from XML files

Recommend this page to a friend!
  Info   View files Documentation   View files View files (2)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not enough user ratingsTotal: 264 All time: 7,762 This week: 347Up
Version License PHP version Categories
i18n_t 1.0.1GNU General Publi...5Localization
Description 

Author

This class can translate application texts loaded from XML files.

It can load application texts for a given application context and language from XML files in the languages directory.

The class returns given strings translated the loaded language.

The class use two levels XML files to translate. It can load one or more files.

With the second level you can even use number comparison for plural forms (zero, one or more than one for example).

It can also use one or more translation files.

Picture of Lionel F. Lebeau
  Performance   Level  
Name: Lionel F. Lebeau <contact>
Classes: 4 packages by
Country: France France
Age: 63
All time rank: 245268 in France France
Week rank: 312 Up15 in France France Up
Innovation award
Innovation award
Nominee: 2x

Recommendations

Documentation

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'));

  Files folder image Files  
File Role Description
Plain text file class.dictionnaires.php Class Translation class
Accessible without login Plain text file readme Doc. How to use this class

 Version Control Reuses Unique User Downloads Download Rankings  
 0%1
Total:264
This week:0
All time:7,762
This week:347Up