开发者

PHP gettext does not work

开发者 https://www.devze.com 2023-03-13 18:15 出处:网络
Gettext simply does not work for me: putenv(\'LC_ALL=zh_CN.utf8\'); setlocale(LC_ALL, \'zh_CN.utf8\'); bindtextdomain(\'messages\', __DIR__.\'/locale\');

Gettext simply does not work for me:

    putenv('LC_ALL=zh_CN.utf8');
    setlocale(LC_ALL, 'zh_CN.utf8');
    bindtextdomain('messages', __DIR__.'/locale');
    textdomain('messages');

messages.mo location is locale/zh_CN.utf8/LC_MESSAGES.

$locale 开发者_如何学编程-a
C
en_AG
en_US.utf8
en_ZA.utf8
en_ZW.utf8
POSIX
zh_CN.utf8
zh_SG.utf8

I'm on Ubuntu.

Any idea?


Judging this note, you are most likely missing UTF-8 bits. Those helped me with problem of “Gettext not working”.

$directory = dirname(__FILE__).'/locale';
$domain = 'mydomain';

$locale ="fi_FI.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');

Inside locale, there should be file structure of

./locale/pt/LC_MESSAGES/mydomain.mo

or similar.

Important: If the mo file is already read by Apache, it needs be restarted so that it can read the new file. In other words, there is some kind of caching system I don’t know about still.


For me, it worked by restarting apache.

0

精彩评论

暂无评论...
验证码 换一张
取 消