Studying use of gettext for WiKiss internationalisation (FS#37).
- used system, very efficient
- most hosting have it ?
- easy for translators (lot of tools availables)
- automatic treatment of missing messages
- hours to understand how it works :)
- gettext pgp extension must be installed
- the concerned locale must be installed in the hosting system
- .mo files are system dependents (linux/windows)
- the locale name differs from the language code (en, en_US)
→ test which locales are installed on some hosting platforms
Here's a list of hosting providers and their installed locales.
For listed linux distibutions, I used standard install, without any configuration.
→ See up-to-date table in french version
Under linux, the command local -a will be more verbose.
This php script test installation of some locales. To use it, you just have to copy it to your hosting platform and display it in your web browser eg: http://wikiss.tuxfamily.org/test/test_gettext.php Then it should be great if you can copy the result and send it to me on the WiKiss Listes with the name of your hosting provider.
<?php
$testlangs = array('fr','fr_FR','fr_BE','fr_CA','en','en_US','en_GB','es','es_ES','de','de_DE','nl','nl_NL');
function testlocale($lang)
{
putenv("LANGUAGE=$lang");
$dir=setlocale(LC_ALL, $lang);
if ($dir == $lang)
return "<li>$lang : OK</li>\n";
else
return "";
}
if (extension_loaded('gettext'))
{
echo 'gettext is installed. Testing some locales ...<br/><ul>';
foreach ($testlangs as $lang)
{
echo testlocale($lang);
echo testlocale($lang.'.utf8');
echo testlocale($lang.'.iso885915');
echo testlocale($lang.'.iso88591');
}
echo '</ul>';
}
else
echo 'gettext is not installed :(';
?>
If you want to test some more locales, just had them to the testlangs array. Here's a minimal code exemple :
// Choose language
$domain="messages";
$lang = 'en_US.utf8';
putenv("LANGUAGE=$lang");
$dir=setlocale(LC_ALL, $lang);
echo 'setlocal:'.$dir."<br/>"; // if string is empty, the locale is not installed and gettext won't work :(
// Specify place of translation tables
bindtextdomain("$domain", "./locale");
// Choose domain
$dir=textdomain("$domain");
echo gettext('Aide');
// should display Help :)
With this code, the locale file must be : ./locale/en_US/LC_MESSAGES/messages.mo
To create .po file from the php code :
xgettext --language=PHP --default-domain=messages --from-code=UTF-8 index.php
To compile the .mo file :
msgfmt -o locale/en_US/LC_MESSAGES/messages.mo locale/en_US/LC_MESSAGES/messages.po
%%
|