Translation2_Admin is a class meant to help with translation management (add/remove a language, add/remove a string).
This simple example will show how you can add a new language [addLang()], using the MDB2 driver:
// set the parameters to connect to your db
$dbinfo = array(
'hostspec' => 'host',
'database' => 'dbname',
'phptype' => 'mysql',
'username' => 'user',
'password' => 'pwd'
);
// tell Translation2 about your db-tables structure,
// if it's different from the default one.
$params = array(
'langs_avail_table' => 'langs_avail',
'lang_id_col' => 'id',
'lang_name_col' => 'name',
'lang_meta_col' => 'meta',
'lang_errmsg_col' => 'error_text',
'lang_encoding_col' => 'encoding',
'strings_tables' => array(
'it' => 'i18n',
'de' => 'i18n'
),
//OR, if you use only one table,
//'strings_default_table' => 'i18n',
'string_id_col' => 'id',
'string_page_id_col' => 'page_id',
'string_text_col' => '%s' //'%s' will be replaced by the lang code
);
$driver = 'MDB2';
require_once 'Translation2/Admin.php';
$tr =& Translation2_Admin::factory($driver, $dbinfo, $params);
// set some info about the new lang
$newLang = array(
'lang_id' => 'en',
'table_name' => 'i18n',
'name' => 'english',
'meta' => 'some meta info',
'error_text' => 'not available',
'encoding' => 'iso-8859-1',
);
$tr->addLang($newLang); |
This simple example will show how you can update an existing language [updateLang()]:
// set some info about the new lang
$langData = array(
'lang_id' => 'en',
'table_name' => 'i18n',
'name' => 'English',
'meta' => 'some updated meta info',
'error_text' => 'this text is not available in English',
'encoding' => 'iso-8859-15',
);
$tr->updateLang($langData); |
If you want to remove all the translated strings and the info for a certain language, all you have to do is
$tr->removeLang('fr'); |
$tr->removeLang('fr', true); |
Now let's see how we can add() a new translation for a new or an existing string.
$stringArray = array(
'en' => 'sample',
'it' => 'esempio',
);
// add the English and Italian translations associated to
// the 'smallTest' stringID and to the 'testGroup' pageID
$tr->add('smallTest', 'testGroup', $stringArray); |
You can remove() the translations for a certain stringID:
$tr->remove('smallTest', 'testGroup'); |