PHP Classes

oLoc: Retrieve and edit internationalized texts

Recommend this page to a friend!
  Info   View files Example   View files View files (133)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not enough user ratingsTotal: 819 All time: 4,214 This week: 206Up
Version License PHP version Categories
oloc 1.0GNU General Publi...3.0Localization, PHP 5
Description 

Author

This package can be used to retrieve and edit internationalized application texts.

It consists of a run-time class and other classes and scripts for editing translations.

The run-time class that retrieves text translations from XML files.

It takes an identifier of a text to retrieve, the path of the directory of the translated text XML files, the text idiom and the default idiom in case the translated text is not defined for the specified idiom.

The editor classes and scripts provide an AJAX based interface for editing texts to translate applications for the different supported idioms.

It allows the user to enter the translation for each application text, or upload a whole translation template file which should be in the Excel format.

Innovation Award
PHP Programming Innovation award nominee
December 2007
Number 5


Prize: One book of choice by Packt
Localization is the process of adapting software programs to the users local idiom and other details of each world country or region.

Localization often consists on translating the texts used in the messages presented to the users of the programs. Depending on the size of the application, the effort to localize it may not be trivial.

This package provides an AJAX based Web interface to help translating the texts used in PHP Web applications, thus reducing the localization efforts.

Manuel Lemos
Picture of Johan Barbier
Name: Johan Barbier <contact>
Classes: 17 packages by
Country: France France
Age: 52
All time rank: 402 in France France
Week rank: 270 Down8 in France France Down
Innovation award
Innovation award
Nominee: 6x

Example

<?php
/**
 * Example on how to use oLocale class
 * I used the file in templates/ and uploaded it in the backoffice. These are some of its translations.
 * I have put a locales/ folder at the root of the package.
 * This locales/ folder should be at the root of the web application you want to localize, of course.
 * You just take it from the websites/name_of_your_website/ backoffice folder.
 * Here, I mixed both the backoffice and the oLoc class, but you should keep the backoffice on your computer probably, create your localizations, and upload websites/name_of_your_website/locales folder to the root of the website you want to localize.
 */
require_once 'inc/inc.main.php';

$oLoc = new oLocale('FRA');
echo
'In French : '.$oLoc->getMsg('mx_play1').'<br />';
$oLoc->LOCALE = 'BGR';
echo
'In Bulgarian : '.$oLoc->getMsg('mx_play1').'<br />';
$oLoc->LOCALE = 'CZE';
echo
'In Czech : '.$oLoc->getMsg('mx_play1').'<br />';
$oLoc->LOCALE = 'ENG';
echo
'In English : '.$oLoc->getMsg('mx_play1').'<br />';
?>


Details

FRENCH Ce package comprend 2 outils distincts mais liés. Ils nécessitent tous deux PHP5, avec 5.1 pour le back-office. - la classe oLocale permettant de gérer l'affichage des traducstions sur un site multilingue. Elle se base sur un flux XML ayant une structure simple, mais bien précise. Elle a besoin d'une langue demandée, et d'une langue par défaut (dans les deux cas, la classe les fixe à l'anglais si ces 2 paramètres ne sont pas passés), et d'un chemin où aller chercher les fichiers de traduction. Par défaut, le chemin est 'locales/'. La structure de ce répertoire doit être respectée, par contre. Si elle ne trouve pas une traduction dans la langue demandée, elle affichera automatiquement la traduction dans la langue par défaut. Elle permet aussi de changer de langue (langue par défaut et langue demandée) en cours de script, sur une même page. Un exemple d'utilisation basique se situe dans le fichier oloc.example.php. De toute manière, la classe est simple d'utilisation. Elle ne possède que 2 méthodes appelables : oLocale::getMsg() permettant d'aller chercher une traduction, et oLocale::getLoc() renvoyant la langue courante. Et 2 propriétés initialisable : oLocale::LOCALE est la langue courante, oLocale::DEFAULT est la langue par défaut. - une application back-office pour gérer ses traductions. Elle se lance via le fichier back.office.php. Une aide en ligne sommaire mais complète est disponible sur l'interface. Ce back-office permet de créer des traductions pour autant de sites que vous le voulez, de gérer des modules de traduction, et des constantes de traduction (chaque message, en fait). Et ce, soit manuellement, soit via l'upload d'un fichier respectant le modèle présent dans le répertoire 'templates/'. Il s'agit d'un fichier Excel. Le back-office ne supporte que ce template, et un process bien défini : il FAUT utiliser ce template, puis il FAUT utiliser OpenOffice (version 2.3 pour moi, à tester avec d'autres versions) pour sauvegarder ce fichier en HTML (et pas XHTML), et c'est ce fichier HTML obtenu que l'on uploadera dans le back-office. J'ai externalisé tout le process de parsing de fichier, ce qui rend "facile" la création d'un nouveau template si vous désirez changer de process, et donc le parsing à appliquer. Il y a 2 classes pour cela : 'class/class.genparser.php' qui ne devrait pas être touchée, elle gère l'upload et diverses petites choses. Et une classe spécialisée 'class/class.openoffice23htmlparser.php' qui étend genparser. Il vous faudra créer la votre si vous voulez changer de modèle. Le back-office est livré avec un "site" test, contenant 2 modules, et leurs traductions dans un paquet de langues (Bulgare, Grec, Tchèque, anglais, allemand, français etc...). Vous pouvez donc afficher les traductions, les modifier, etc...afin de tester l'application. Toute l'interface utilise Ajax (upload mis à part) pour une ergonomie plus agréable. A noter que pour le moment, je n'ai pas réussi à faire tourner cette application (je parle uniquement du back-office là) sur IE. Il n'y a pas grand chose à modifier mais je n'ai pas encore trouvé l'astuce pour faire ça simplement (IE et le DOM, décidément...). Testé sur Firefox 2, Opera 9, Flock 1. ENGLISH This package provides 2 different, but linked, tools. For both of them, PHP5 is mandatory, and PHP5.1 fopr the back-office. - Class oLocale allows to manage the display of translations on a localized web application. It's based on an XML feed which structure is simple but must be respected. It needs the asked language, a default language (in both cases, if none is provided, English is set to default), and a path where to find localization files. Default path is 'locales/'. The folder structure must be kept. If oLocale does not find a trabslation in the current language, it will automatically switch to default language for this translation. It allows you to change languages (current and default) in the same script. A basic example is provided in the file 'oloc.example.php'. But anyway, its use if very easy : 2 methods are callable : oLocale::getMsg() which fetches and returns a translation oLocale::getLoc() which returns current language And 2 settable/gettable properties: oLocale::LOCALE which allows you to change current language oLocale::DEFAULT which allows you to change default language - a back-office application to manage your translations. It's launched via file 'back.office.php'. A basic but complete online help is available on the back-office. This application allows you to create translations for as many "sites" you need, to manage translation modules, and constants modules (each message, indeed). You can do this either manually or by uploading a file. This file must be based on the template file you'll find in the 'templates/' folder. It's an Excel file. This back-office, right now, does support only this template, and a defined process : you MUST use this template, then you MUST open it with OpenOffice (version 2.3 for me, but you can try with another one, with no guarantee it will work however), then you MUST save this file as an HTML file (HTML, NOT XHTML), and it's THIS file you will upload in the back-office. The parser classes are outside the back-office, so you can "easily" create your own templates. To do that, you have 2 files : 'class/class.genparser.php' which should not need to be modified. Ut manages upload and other small stuff. 'class/class.openoffice23htmlparser.php' which extends genparser. This one, you'll have to modify if you want to create your own template. The back-office provides an example "site" which contains 2 modules and their translations in many languages (Bulgarian, Greek, Czech, English, German, French...); you can thus display these translations, modify them and do whatever you want to do! Well, test the application! The GUI is full AJax (only not the upload part). I used Protoype to help coding the javascript. You will also find in the 'countries/' folder an XML file which provide the names of all the countries in the world in 7 languages, as well as their ISO 3166-1 alpha2 and alpha3 codes, and a function of my own which return these codes, given a country name. Can be handy. It's used by genparser anyway. This version (20071101) is not supported by IE. Ther's not much to do, but I did not find the easy way to make it work on that browser. Tested on Firefox 2, Opera 9, Flock 1.

  Files folder image Files  
File Role Description
Files folder imageajax (6 files)
Files folder imageclass (7 files)
Files folder imagecountries (2 files)
Files folder imagecss (1 file)
Files folder imageimg (3 files)
Files folder imageinc (1 file)
Files folder imagejs (2 files)
Files folder imagelocales (26 directories)
Files folder imagetemplates (1 file)
Files folder imagetmp (1 file)
Files folder imagewebsites (1 directory)
Accessible without login Plain text file back.office.php Appl. Back-Office application
Plain text file oloc.example.php Example oLocale class example
Plain text file readme.txt Doc. Documentation

  Files folder image Files  /  ajax  
File Role Description
  Plain text file ajax.back.office.add.constant.php Appl. Ajax script
  Plain text file ajax.back.office.del.constant.php Appl. Delete a translation
  Accessible without login Plain text file ajax.back.office.display.list.php Appl. Ajax script
  Plain text file ajax.back.office.get.websites.php Appl. Ajax script
  Accessible without login Plain text file ajax.back.office.update.toolz.menu.php Appl. Ajax script
  Plain text file ajax.back.office.update.value.php Appl. Ajax script

  Files folder image Files  /  class  
File Role Description
  Accessible without login Plain text file class.backoffice.php Class Back Office main class
  Accessible without login Plain text file class.genparser.php Class Back Office auxiliary class
  Plain text file class.localeException.php Class oLocale specific Exceptions
  Plain text file class.oLocale.php Class oLocale class
  Accessible without login Plain text file class.openoffice23htmlparser.php Class Soecific class for parsing HTML files from sCalc in OpenOffice
  Plain text file package.exceptions.errors.php Class Errors to Exceptions class
  Plain text file package.exceptions.php Class Exceptions class

  Files folder image Files  /  countries  
File Role Description
  Plain text file countries.xml Data Countries XML file
  Plain text file get.alpha.cn.php Aux. Function used to retrieve iso 3166-1 alpha codes

  Files folder image Files  /  css  
File Role Description
  Plain text file back.office.css Data Back Office css file

  Files folder image Files  /  img  
File Role Description
  Image file add16.png Icon Image
  Image file delete16.png Data Button
  Image file help32.png Icon Image

  Files folder image Files  /  inc  
File Role Description
  Plain text file inc.main.php Conf. Configuration file

  Files folder image Files  /  js  
File Role Description
  Accessible without login Plain text file back.office.js Data JS script
  Plain text file prototype.js Data Prototype library

  Files folder image Files  /  locales  
File Role Description
Files folder imageBEL (2 files)
Files folder imageBGR (2 files)
Files folder imageCHE (2 files)
Files folder imageCZE (2 files)
Files folder imageDNK (2 files)
Files folder imageENG (2 files)
Files folder imageESP (2 files)
Files folder imageEST (2 files)
Files folder imageFIN (2 files)
Files folder imageFRA (2 files)
Files folder imageGER (2 files)
Files folder imageGRC (2 files)
Files folder imageHRV (2 files)
Files folder imageHUN (2 files)
Files folder imageITA (2 files)
Files folder imageLITHUANIE (2 files)
Files folder imageLVA (2 files)
Files folder imageNLD (2 files)
Files folder imageNORVEGE (2 files)
Files folder imagePOL (2 files)
Files folder imagePRT (2 files)
Files folder imageROU (2 files)
Files folder imageRUSSIE (2 files)
Files folder imageSLOVENIE (2 files)
Files folder imageSUEDE (2 files)
Files folder imageSVK (2 files)

  Files folder image Files  /  locales  /  BEL  
File Role Description
  Plain text file err.xml Data Localized module
  Plain text file mx.xml Data Localized module

  Files folder image Files  /  locales  /  BGR  
File Role Description
  Plain text file err.xml Data Localized module
  Plain text file mx.xml Data Localized module

  Files folder image Files  /  locales  /  CHE  
File Role Description
  Plain text file err.xml Data Localized module
  Plain text file mx.xml Data Localized module

  Files folder image Files  /  locales  /  CZE  
File Role Description
  Plain text file err.xml Data localized module
  Plain text file mx.xml Data Localized module

  Files folder image Files  /  locales  /  DNK  
File Role Description
  Plain text file err.xml Data Localized module
  Plain text file mx.xml Data Localized module

  Files folder image Files  /  locales  /  ENG  
File Role Description
  Plain text file err.xml Data Localized module
  Plain text file mx.xml Data Localized module

  Files folder image Files  /  locales  /  ESP  
File Role Description
  Plain text file err.xml Data Localized module
  Plain text file mx.xml Data Localized module

  Files folder image Files  /  locales  /  EST  
File Role Description
  Plain text file err.xml Data Localized module
  Plain text file mx.xml Data Localized module

  Files folder image Files  /  locales  /  FIN  
File Role Description
  Plain text file err.xml Data Localized module
  Plain text file mx.xml Data Localized module

  Files folder image Files  /  locales  /  FRA  
File Role Description
  Plain text file err.xml Data Localized module
  Plain text file mx.xml Data Localized module

  Files folder image Files  /  locales  /  GER  
File Role Description
  Plain text file err.xml Data Localized module
  Plain text file mx.xml Data Localized module

  Files folder image Files  /  locales  /  GRC  
File Role Description
  Plain text file err.xml Data Localized module
  Plain text file mx.xml Data Localized module

  Files folder image Files  /  locales  /  HRV  
File Role Description
  Plain text file err.xml Data Localized module
  Plain text file mx.xml Data Localized module

  Files folder image Files  /  locales  /  HUN  
File Role Description
  Plain text file err.xml Data Localized module
  Plain text file mx.xml Data Localized module

  Files folder image Files  /  locales  /  ITA  
File Role Description
  Plain text file err.xml Data Localized module
  Plain text file mx.xml Data Localized module

  Files folder image Files  /  locales  /  LITHUANIE  
File Role Description
  Plain text file err.xml Data Localized module
  Plain text file mx.xml Data Localized module

  Files folder image Files  /  locales  /  LVA  
File Role Description
  Plain text file err.xml Data Localized module
  Plain text file mx.xml Data Localized module

  Files folder image Files  /  locales  /  NLD  
File Role Description
  Plain text file err.xml Data Localized module
  Plain text file mx.xml Data Localized module

  Files folder image Files  /  locales  /  NORVEGE  
File Role Description
  Plain text file err.xml Data Localized module
  Plain text file mx.xml Data Localized module

  Files folder image Files  /  locales  /  POL  
File Role Description
  Plain text file err.xml Aux. Localized module
  Plain text file mx.xml Data Localized module

  Files folder image Files  /  locales  /  PRT  
File Role Description
  Plain text file err.xml Data Localized module
  Plain text file mx.xml Data Localized module

  Files folder image Files  /  locales  /  ROU  
File Role Description
  Plain text file err.xml Data Localized module
  Plain text file mx.xml Data Localized module

  Files folder image Files  /  locales  /  RUSSIE  
File Role Description
  Plain text file err.xml Data Localized module
  Plain text file mx.xml Data Localized module

  Files folder image Files  /  locales  /  SLOVENIE  
File Role Description
  Plain text file err.xml Data Localized module
  Plain text file mx.xml Data Localized module

  Files folder image Files  /  locales  /  SUEDE  
File Role Description
  Plain text file err.xml Data Localized module
  Plain text file mx.xml Data Localized module

  Files folder image Files  /  locales  /  SVK  
File Role Description
  Plain text file err.xml Data Localized module
  Plain text file mx.xml Data Localized module

  Files folder image Files  /  templates  
File Role Description
  Plain text file template.xls Data Translation upload file template AFTER saving it as HTML

  Files folder image Files  /  tmp  
File Role Description
  Plain text file template_test.html Data Uploaded file after parsing

  Files folder image Files  /  websites  
File Role Description
Files folder imagewww.myweb.com (1 directory)

  Files folder image Files  /  websites  /  www.myweb.com  
File Role Description
Files folder imagelocales (27 directories)

  Files folder image Files  /  websites  /  www.myweb.com  /  locales  
File Role Description
Files folder imageBEL (2 files)
Files folder imageBGR (2 files)
Files folder imageCHE (2 files)
Files folder imageCZE (2 files)
Files folder imagedefault (2 files)
Files folder imageDNK (2 files)
Files folder imageENG (2 files)
Files folder imageESP (2 files)
Files folder imageEST (2 files)
Files folder imageFIN (2 files)
Files folder imageFRA (2 files)
Files folder imageGER (2 files)
Files folder imageGRC (2 files)
Files folder imageHRV (2 files)
Files folder imageHUN (2 files)
Files folder imageITA (2 files)
Files folder imageLITHUANIE (2 files)
Files folder imageLVA (2 files)
Files folder imageNLD (2 files)
Files folder imageNORVEGE (2 files)
Files folder imagePOL (2 files)
Files folder imagePRT (2 files)
Files folder imageROU (2 files)
Files folder imageRUSSIE (2 files)
Files folder imageSLOVENIE (2 files)
Files folder imageSUEDE (2 files)
Files folder imageSVK (2 files)

  Files folder image Files  /  websites  /  www.myweb.com  /  locales  /  BEL  
File Role Description
  Plain text file err.xml Data websites/www.myweb.com/locales/BEL/err.xml
  Plain text file mx.xml Data Loc

  Files folder image Files  /  websites  /  www.myweb.com  /  locales  /  BGR  
File Role Description
  Plain text file err.xml Data Loc
  Plain text file mx.xml Data Loc

  Files folder image Files  /  websites  /  www.myweb.com  /  locales  /  CHE  
File Role Description
  Plain text file err.xml Data LOC
  Plain text file mx.xml Data Loc

  Files folder image Files  /  websites  /  www.myweb.com  /  locales  /  CZE  
File Role Description
  Plain text file err.xml Data Loc
  Plain text file mx.xml Data Loc

  Files folder image Files  /  websites  /  www.myweb.com  /  locales  /  default  
File Role Description
  Plain text file err.xml Data Default module definition
  Plain text file mx.xml Data Default module definition

  Files folder image Files  /  websites  /  www.myweb.com  /  locales  /  DNK  
File Role Description
  Plain text file err.xml Data Loc
  Plain text file mx.xml Data Loc

  Files folder image Files  /  websites  /  www.myweb.com  /  locales  /  ENG  
File Role Description
  Plain text file err.xml Data Loc
  Plain text file mx.xml Data Loc

  Files folder image Files  /  websites  /  www.myweb.com  /  locales  /  ESP  
File Role Description
  Plain text file err.xml Data Loc
  Plain text file mx.xml Data Loc

  Files folder image Files  /  websites  /  www.myweb.com  /  locales  /  EST  
File Role Description
  Plain text file err.xml Data Loc
  Plain text file mx.xml Data Loc

  Files folder image Files  /  websites  /  www.myweb.com  /  locales  /  FIN  
File Role Description
  Plain text file err.xml Data Loc
  Plain text file mx.xml Data Loc

  Files folder image Files  /  websites  /  www.myweb.com  /  locales  /  FRA  
File Role Description
  Plain text file err.xml Data Loc
  Plain text file mx.xml Data Loc

  Files folder image Files  /  websites  /  www.myweb.com  /  locales  /  GER  
File Role Description
  Plain text file err.xml Data Loc
  Plain text file mx.xml Data Loc

  Files folder image Files  /  websites  /  www.myweb.com  /  locales  /  GRC  
File Role Description
  Plain text file err.xml Data Loc
  Plain text file mx.xml Data Loc

  Files folder image Files  /  websites  /  www.myweb.com  /  locales  /  HRV  
File Role Description
  Plain text file err.xml Data Loc
  Plain text file mx.xml Data loc

  Files folder image Files  /  websites  /  www.myweb.com  /  locales  /  HUN  
File Role Description
  Plain text file err.xml Data loc
  Plain text file mx.xml Data loc

  Files folder image Files  /  websites  /  www.myweb.com  /  locales  /  ITA  
File Role Description
  Plain text file err.xml Data loc
  Plain text file mx.xml Data Loc

  Files folder image Files  /  websites  /  www.myweb.com  /  locales  /  LITHUANIE  
File Role Description
  Plain text file err.xml Data Loc
  Plain text file mx.xml Data loc

  Files folder image Files  /  websites  /  www.myweb.com  /  locales  /  LVA  
File Role Description
  Plain text file err.xml Data Loc
  Plain text file mx.xml Data Loc

  Files folder image Files  /  websites  /  www.myweb.com  /  locales  /  NLD  
File Role Description
  Plain text file err.xml Data Loc
  Plain text file mx.xml Data Loc

  Files folder image Files  /  websites  /  www.myweb.com  /  locales  /  NORVEGE  
File Role Description
  Plain text file err.xml Data Loc
  Plain text file mx.xml Data Loc

  Files folder image Files  /  websites  /  www.myweb.com  /  locales  /  POL  
File Role Description
  Plain text file err.xml Data Loc
  Plain text file mx.xml Data Loc

  Files folder image Files  /  websites  /  www.myweb.com  /  locales  /  PRT  
File Role Description
  Plain text file err.xml Data Loc
  Plain text file mx.xml Data Loc

  Files folder image Files  /  websites  /  www.myweb.com  /  locales  /  ROU  
File Role Description
  Plain text file err.xml Data Loc
  Plain text file mx.xml Data Loc

  Files folder image Files  /  websites  /  www.myweb.com  /  locales  /  RUSSIE  
File Role Description
  Plain text file err.xml Data Loc
  Plain text file mx.xml Data Loc

  Files folder image Files  /  websites  /  www.myweb.com  /  locales  /  SLOVENIE  
File Role Description
  Plain text file err.xml Data Loc
  Plain text file mx.xml Data Loc

  Files folder image Files  /  websites  /  www.myweb.com  /  locales  /  SUEDE  
File Role Description
  Plain text file err.xml Data Loc
  Plain text file mx.xml Data Loc

  Files folder image Files  /  websites  /  www.myweb.com  /  locales  /  SVK  
File Role Description
  Plain text file err.xml Data Loc
  Plain text file mx.xml Data Loc

 Version Control Unique User Downloads Download Rankings  
 0%
Total:819
This week:0
All time:4,214
This week:206Up