【问题标题】:PHP gettext does not workPHP gettext 不起作用
【发布时间】:2011-09-17 22:35:36
【问题描述】:

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 上。

有什么想法吗?

【问题讨论】:

  • 它没有以您想与我们分享的特定方式工作吗?
  • @Álvaro 不。它体现在 gettext() 和 _() 返回原始文本而不是翻译。
  • 试试:bindtextdomain('messages', __DIR__.'/locale');,也许有帮助。我认为你需要完整的路径。
  • 这就是我所做的,只是为了更短的写作而粘贴了这个。我最后硬编码了完整路径。将编辑问题以避免混淆,谢谢。
  • “你想和我们分享”lolol +1

标签: php ubuntu locale gettext


【解决方案1】:

判断 this note,您很可能缺少 UTF-8 位。这些帮助我解决了“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');

在locale里面,应该有

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

或类似的。

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

【讨论】:

  • 我花时间解决了 Statusnet(status.net - 它使用 gettext)不显示我的语言的问题。我在这里找到了答案!运行“make”(生成 *.mo 文件)后,我需要重新启动 Apache。现在一切正常。
【解决方案2】:

对我来说,它通过重新启动 apache 来工作。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-04-22
    • 1970-01-01
    • 2012-09-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多