Translation2 supports different storage drivers; this page is meant to highlight the differences among them.
Translation2 can work with any of these database abstraction layers, just pass the appropriate connection options. These three containers are absolutely identical in what they do and in how they work (wrt Translation2, of course).
// connection options
$dbinfo = array(
'hostspec' => 'host',
'database' => 'dbname',
'phptype' => 'mysql',
'username' => 'user',
'password' => 'pwd'
//select the preferred driver
$driver = 'MDB2'; //switch to 'DB' or 'MDB' as needed
$tr =& Translation2::factory($driver, $dbinfo, $params);
If your table definition is different from the default one, you need to
specify it in the
dataobjectsimple container is the natural choice
for those using
as it is tightly tied to the DAO. This storage driver can use all databases supported by
abstraction layer to fetch data.
For this container, you can't specify a custom table definition, since this feature is not supported yet. You must create a table with the following structure:
Here's the MySQL query that can be used to create the table:
then just run the dataobjects createtables script.
This is a wrapper around the gettext base functions, and thanks to File_Gettext you can retrieve an entire domain or write to an existing/new domain without calling the command line compiler utility.
The construction parameters are a bit different from the db ones. To make things as simple as possible, the domain definitions and the available language list are read from two INI files.
Sample code to use Translation2 with the gettext container:
$params = array(
'prefetch' => false,
'langs_avail_file' => 'path/to/langs.ini',
'domains_path_file' => 'path/to/domains.ini',
'default_domain' => 'messages',
//'file_type' => 'po',
// Better set prefetch to FALSE for the gettext container, so we don't need
// to read in the whole MO file with File_Gettext on every request.
$tr =& Translation2::factory('gettext', $params);
// Note that, if there is no translation available for a string, the gettext
// container will return the string ID! This behaviour emulates native gettext.
The XML container requires PEAR::XML_Serializer 0.13.0 or newer, make sure you have it installed.
$driver = 'XML';
$options = array(
'filename' => 'i18n.xml',
'save_on_shutdown' => true, //set to FALSE to save in real time
$tr =& Translation2::factory($driver, $options);