<?php
header( 'Content-Type: text/html; charset=utf-8' );

error_reporting( E_ALL |  E_STRICT );
require '../patI18n.php';

echo "<h3>Add i18n modules</h3>";

// Internal
$moduleConf =   array();
echo 'add Module: Internal<pre>' . print_r( $moduleConf, true ) . '</pre>';
patI18n::addModule( 'Internal', $moduleConf );

// Gettext
$moduleConf    =   array(
            'domain'    =>  'patI18n',
            'dir'       =>  dirname( __FILE__ ) . '/data/gettext/mo',
            'domains'   =>  array(
                array(
                        'domain'    =>  'patForms',
                        'dir'       =>  dirname( __FILE__ ) . '/data/gettext/mo',
                    )
                )
    );
echo 'add Module: Gettext<pre>' . print_r( $moduleConf, true ) . '</pre>';
patI18n::addModule( 'Gettext', $moduleConf );

echo "<hr />";

echo "<h3>Set current locale</h3>";
// set language to de_DE
patI18n::setLocale( 'de_DE' );

echo "<hr />";
echo "<h3>Translate string of the default domain</h3>";
echo patI18n::gettext( 'This text is translated' ), '<br />';
echo patI18n::gettext( 'Sometimes there is no translation at all!' ), '<br />';
echo patI18n::ngettext( 'Translate me, please!', 'Translate us, please!', 1 ), '<br />';
echo patI18n::ngettext( 'Translate me, please!', 'Translate us, please!', 7 ), '<br />';

?>
<hr />
<h3>How to use those funny gettext tools</h3>
<p>
Extract POT file from source code
<pre>
$ xgettext -o data/gettext/po/patI18n.pot a01.php
</pre>
</p>
<p>
Update German (de) translation.
<pre>
$ msgmerge -U data/gettext/po/patI18n/de.po data/gettext/po/patI18n.pot
</pre>
Edit the "de.po" file - in other words, translate untranlated or fuzzy string.
To do so, use either you favourite text- or special catalog-editor, like
<a href="http://www.poedit.net/" title="poEdit is cross-platform gettext catalogs (.po files) editor.">PO Edit</a> 
or 
<a href="http://kbabel.kde.org/" title="KBabel is a set of tools for editing and managing gettext PO files">Kbabel</a>.
</p>

<p>
Validate message catalog (PO file)
<pre>
$ msgfmt --statistics --check  data/gettext/po/patI18n/de.po -o /tmp/rubish.mo
</pre>
</p>

<p>
Create binary catalog (MO file) from message catalog (PO file)
<pre>
$ msgfmt --statistics --check data/gettext/po/patI18n/de.po -o data/gettext/mo/de/LC_MESSAGES/patI18n.mo
</pre>
</p>

