*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
setlocale( LC_MESSAGES, 'pt_BR')
setlocale( LC_MESSAGES, 'pt_BR.utf8')
setlocale( LC_MESSAGES, '')
putenv("LANG=pt_BR.utf8");
putenv("LANGUAGE=pt_BR.utf8");
bindtextdomain('mydomain', dirname(__FILE__).'/locale');
bindtextdomain("*", dirname(__FILE__).'/locale');
bindtextdomain('*', dirname(__FILE__).'/locale');
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";
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