Admin Introduction

Admin Introduction -- Usage of Translation2_Admin

What is Translation2_Admin?

Translation2_Admin is a class meant to help with translation management (add/remove a language, add/remove a string).

Adding a new language

This simple example will show how you can add a new language [createNewLang()], 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',
    'strings_tables'  => array(
                            'it' => 'i18n',
                            'de' => 'i18n'
                         ),
    'string_id_col'      => 'ID',
    'string_page_id_col' => 'pageID',
    'string_text_col'    => '%s'  //'%s' will be replaced by the lang code
);

$driver = 'MDB2';

require_once 'Translation2/Admin.php';
$tr = new Translation2_Admin($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');
);

$tr->createNewLang($newLang);
That's it. If you specified a new table, it will be created, if you used the same table name as the one of your other translations, it will be ALTERed to host the new language too.

Removing an existing language

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');
removeLang() can accept a 2nd parameter ($force): if you want to remove the whole strings table (regardless it being used for other languages as well), you can do it this way:
$tr->removeLang('fr', true);
Be warned it won't do any check, so you're responsible for what you do ;-)

Adding new translations

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

Remove a translation

You can remove() the translations for a certain stringID:
$tr->remove('smallTest', 'testGroup');