note 91650 added to book.gettext

From: Date: Sun, 21 Jun 2009 18:30:07 +0000
Subject: note 91650 added to book.gettext
Groups: php.notes 
Request: Send a blank email to php-notes+get-157199@lists.php.net to get a copy of this message
*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 ---- Server IP: 208.69.120.35 Probable Submitter: 189.31.127.108 ---- Manual Page -- http://www.php.net/manual/en/book.gettext.php Edit -- https://master.php.net/note/edit/91650 Del: integrated -- https://master.php.net/note/delete/91650/integrated Del: useless -- https://master.php.net/note/delete/91650/useless Del: bad code -- https://master.php.net/note/delete/91650/bad+code Del: spam -- https://master.php.net/note/delete/91650/spam Del: non-english -- https://master.php.net/note/delete/91650/non-english Del: in docs -- https://master.php.net/note/delete/91650/in+docs Del: other reasons-- https://master.php.net/note/delete/91650 Reject -- https://master.php.net/note/reject/91650 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#157199) next »