Following text is copied from http://php.net/manual/en/book.gettext.php
"
An important thing to keep in mind:
Do not forget to set the charset in .po file!
For example:
"Content-Type: text/plain; charset=UTF-8\n"
Then PHP will be able to find the .mo file you generated, using msgfmt, from the .po file WITH CHARSET SET.
Because of this I've wasted a lot of time debugging my code, testing every single little changes people suggested over this manual and Internet:
<?php
//this:
setlocale( LC_MESSAGES, 'pt_BR')
//or this:
setlocale( LC_MESSAGES, 'pt_BR.utf8')
//or this:
setlocale( LC_MESSAGES, '')
//this:
putenv("LANG=pt_BR.utf8");
//or this:
putenv("LANGUAGE=pt_BR.utf8");
//this:
bindtextdomain('mydomain', dirname(__FILE__).'/locale');
//or this:
bindtextdomain("*", dirname(__FILE__).'/locale');
//or this:
bindtextdomain('*', dirname(__FILE__).'/locale');
//setting or not "bind_textdomain_codeset()":
bind_textdomain_codeset("mydomain", 'UTF-8');
?>
As well as what locale directory name to set:
./locale/pt_BR.UTF8/LC_MESSAGES/mydomain.mo
or
./locale/pt_BR/LC_MESSAGES/mydomain.mo
or
./locale/pt/LC_MESSAGES/mydomain.mo
Finally, the code which brought the right translated strings (also with the correct charset) was:
<?php
$directory = dirname(__FILE__).'/locale';
$domain = 'mydomain';
$locale ="pt_BR.utf8";
//putenv("LANG=".$locale); //not needed for my tests, but people say it's useful for windows
setlocale( LC_MESSAGES, $locale);
bindtextdomain($domain, $directory);
textdomain($domain);
bind_textdomain_codeset($domain, 'UTF-8');
?>
And the three directory's names worked out, using the pt_BR.utf8 locale. (My tests were made restarting Apache then trying each directory).
I hope to help someone else not to waste as much time as I've wasted... =P
Using:
Ubuntu 8.04 (hardy)
Apache 2.2.8
PHP 5.2.4-2ubuntu5.6
"