PHP Classes

File: index.php

Recommend this page to a friend!
  Classes of Cristian Navalici   XMLTrans   index.php   Download  
File: index.php
Role: Example script
Content type: text/plain
Description: Demo file (please read it before see it in a browser)
Class: XMLTrans
Manipulate internationalization XML files
Author: By
Last change: Example for new functionality.
Date: 16 years ago
Size: 1,716 bytes


Class file image Download
 * how to use it in your scripts (read this file before run it on your webserver)
 * What you should do first: set the right paths for language files
 * (see $langarr in the first lines of class definition), set the default lang
 * and also set the temporary file path (used at update/delete key - $tempfile)

// include the class file

// create a new object
$ob = new XMLTrans();

// get a translation from the files for english
// 1 means echo, otherwise we should use echo $ob->XT_gettext('three', 'en', 0, XT_ATTR_MIN);
// XT_ATTR_MIN means - the result is returned/echoed with all letters minuscules
// there is also XT_ATTR_MAJ for majuscules
$ob->XT_gettext('three', 'en', 1, XT_ATTR_MIN);

// as an admin, you want to update the value for a key
// in this example we change the value for key 'two' with 'new value'
$ob->XT_updatekey("new value", "two", "en");

// this will display the above value - 'new value'
$ob->XT_gettext('two', 'en', 1);

// add a new key in romanian file
$ob->XT_addkey('Patru', 'four', 'ro');

// add again the same key in romanian file; it returns FALSE
$a = $ob->XT_addkey('Patru', 'four', 'ro');
var_dump($a); //false

// delete a key (two) from english file
$ob->XT_deletekey('two', 'en');

// create a new empty language file
// NOTE: for this moment, the references to files are hardcoded so,
// you should put a reference to it in the class file
$rez = $ob->XT_createfile('nl');
if (
$rez ) $ob->XT_addkey('Vijf', 'five', 'nl');

// List languages
$langs = $ob->XT_list_languages();
var_dump($langs); // it returns something as array(3) { [0]=> string(2) "en" [1]=> string(2) "nl" ... }