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