Saturday 15 March 2014

internationalization - How to generate .po files using translated strigs from a database in php? -



internationalization - How to generate .po files using translated strigs from a database in php? -

i seek create resources files multi language php website. created .po files, converted binary .mo files little library https://github.com/josscrowcroft/php.mo, not seem work. if open generated .po file poedit nail save, observed .mo file size alter little comparing initial 1 , .po file works. not know how working, directly, without using poedit tool.

please give me suggestions if have! thanks

following text copied http://php.net/manual/en/book.gettext.php

" an of import thing maintain in mind: not forget set charset in .po file! example:

"content-type: text/plain; charset=utf-8\n"

then php able find .mo file generated, using msgfmt, .po file charset set.

because of i've wasted lot of time debugging code, testing every single little changes people suggested on manual , 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 locale directory name 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, code brought right translated strings (also right charset) was:

<?php $directory = dirname(__file__).'/locale'; $domain = 'mydomain'; $locale ="pt_br.utf8"; //putenv("lang=".$locale); //not needed tests, people it's useful windows setlocale( lc_messages, $locale); bindtextdomain($domain, $directory); textdomain($domain); bind_textdomain_codeset($domain, 'utf-8'); ?>

and 3 directory's names worked out, using pt_br.utf8 locale. (my tests made restarting apache trying each directory).

i hope help else not waste much time i've wasted... =p

using: ubuntu 8.04 (hardy) apache 2.2.8 php 5.2.4-2ubuntu5.6 "

php internationalization po poedit

No comments:

Post a Comment