PHP gettext不起作用

时间:2011-06-18 21:12:49

标签: php ubuntu locale gettext

Gettext根本不适用于我:

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

messages.mo位置是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

我在Ubuntu上。

有什么想法吗?

2 个答案:

答案 0 :(得分:4)

判断this note,您很可能缺少UTF-8位。那些帮我解决了“Gettext无法正常工作”的问题。

$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');

在语言环境中,应该有

的文件结构
./locale/pt/LC_MESSAGES/mydomain.mo

或类似。

重要提示:如果Apache已经读取了mo文件,则需要重新启动它以便它可以读取新文件。换句话说,还有一些我还不知道的缓存系统。

答案 1 :(得分:0)

对我来说,它通过重启apache来起作用。