【发布时间】:2012-01-23 22:43:47
【问题描述】:
它现在将花费数周时间尝试使其正常工作,但在 Ubuntu 上却不行。 (即使它适用于本地主机......)
这里是选择语言的 PHP 代码。此代码位于以下路径:/srv/d_disk/www/www.domaine.com/htdocs/www/mainsite/index.php
putenv("LANG=$langage");
$directory = dirname(__FILE__).'/locale';
$domain = 'traductions';
$locale=$langage . '.utf8';
setlocale( LC_MESSAGES, $locale);
bindtextdomain($domain, $directory);
textdomain($domain);
bind_textdomain_codeset($domain, 'UTF-8');
变量 $langage 由以下任一填充:fr_FR 或 en_US(我做了一个回显,它更改正确)但屏幕上的语言没有改变。
locale -a 显示已安装语言环境 fr_FR.utf8 和 fr_FR(对于 en_US 相同) .po 和 .mo 可以在这里找到: /srv/d_disk/www/www.domaine.com/htdocs/mainsite/locale/fr_FR.utf8/LC_MESSAGES
我重新编译了 .po 文件: msgfmt -o traductions.mo -v traductions.po
.po 文件如下:
msgid ""
msgstr ""
"Project-Id-Version: test\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2011-11-17 19:41+0100\n"
"PO-Revision-Date: 2011-11-22 20:45+0100\n"
"Last-Translator: \n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"X-Poedit-KeywordsList: _;gettext;gettext_noop;{t}\n"
"X-Poedit-Basepath: ../../../mainsite/presentation/templates\n"
"X-Poedit-SourceCharset: utf-8\n"
"X-Poedit-SearchPath-0: /srv/d_disk/www/www.domaine.com/htdocs/mainsite/presentation/templates\n"
"X-Poedit-SearchPath-1: ../../../mainsite/presentation/templates\n"
#: /srv/d_disk/www/www.domaine.com/htdocs/mainsite/presentation/templates/about-us.c:1
msgid "About Us"
msgstr "A Propos de Nous"
但没有任何改变...
在 phpinfo 中,我有启用 GETTEXT 支持的标签。
一个想法?
EDIT :通过使用 strace 我得到以下 =>
PHP Warning: PHP Startup: Unable to load dynamic library
'/usr/lib/php5/20090626+lfs/gettext.so' - /usr/lib/php5/20090626+lfs/gettext.so:
cannot open shared object file: No such file or directory in Unknown on line 0
Bienvenue<br />Bonne journ?e<br />
EDIT 2:通过删除 gettext.so,我在使用 strace 时有以下内容:
strace -e trace=file -o test.txt php test_hasher.php
Bienvenue
Bonne journ?e
这意味着它在 strace 中被翻译成法语,但在刷新页面时不会(即使在缓存清理和重新启动 apache 之后)
【问题讨论】:
-
为什么你的.po文件以
msgid "" msgstr ""开头? -
我不知道。我刚刚删除了这两行并重新启动了 apache,但它没有帮助。
-
我重新启动了服务器,所以我猜它没有链接到缓存。
-
在您尝试使用 _() 等 gettext 函数之前,您提供的代码是否已运行?