cvs: peardoc /en/package/internationalization/translation2 introadmin.xml
| From: | Lorenzo Alberton | Date: | Mon, 17 May 2004 15:23:09 +0000 |
| Subject: | cvs: peardoc /en/package/internationalization/translation2 introadmin.xml | ||
| Groups: | php.pear.doc | ||
| Request: | Send a blank email to pear-doc+get-4010@lists.php.net to get a copy of this message | ||
quipo Mon May 17 11:23:09 2004 EDT
Added files:
/peardoc/en/package/internationalization/translation2
introadmin.xml
Log:
Translation2_Admin howto
http://cvs.php.net/co.php/peardoc/en/package/internationalization/translation2/introadmin.xml?r=1.1&p=1
Index: peardoc/en/package/internationalization/translation2/introadmin.xml
+++ peardoc/en/package/internationalization/translation2/introadmin.xml
<!-- $Revision: 1.1 $ -->
<refentry id="package.internationalization.translation2.introadmin">
<refnamediv>
<refname>Admin Introduction</refname>
<refpurpose>Usage of
<classname>Translation2_Admin</classname></refpurpose>
</refnamediv>
<refsect1 id="package.internationalization.translation2.introadmin.whatis">
<title>What is Translation2_Admin?</title>
<para>
<classname>Translation2_Admin</classname> is a class meant to help with
translation management (add/remove a language, add/remove a string).
</para>
</refsect1>
<refsect1 id="package.internationalization.translation2.introadmin.addlang">
<title>Adding a new language</title>
<para>
This simple example will show how you can add a new language, using the MDB2 driver:
<programlisting role="php">
<![CDATA[
// 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);
]]>
</programlisting>
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.
</para>
</refsect1>
<refsect1 id="package.internationalization.translation2.introadmin.removelang">
<title>Removing an existing language</title>
<para>
If you want to remove all the translated strings and the info
for a certain language, all you have to do is
<programlisting
role="php">$tr->removeLang('fr');</programlisting>
<function>removeLang</function> 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:
<programlisting role="php">$tr->removeLang('fr',
true);</programlisting>
Be warned it won't do any check, so you're responsible for what you do ;-)
</para>
</refsect1>
<refsect1
id="package.internationalization.translation2.introadmin.addtranslation">
<title>Adding new translations</title>
<para>
Now let's see how we can add a new translation for a new or an existing string.
<programlisting role="php">
<![CDATA[
$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);
]]>
</programlisting>
</para>
</refsect1>
<refsect1
id="package.internationalization.translation2.introadmin.removetranslation">
<title>Remove a translation</title>
<para>
You can remove the translations for a certain stringID:
<programlisting role="php">
<![CDATA[
$tr->remove('smallTest', 'testGroup');
]]>
</programlisting>
</para>
</refsect1>
</refentry>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
sgml-parent-document:nil
sgml-default-dtd-file:"../../../../manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
vim600: syn=xml fen fdm=syntax fdl=2 si
vim: et tw=78 syn=sgml
vi: ts=1 sw=1
-->