我目前正在尝试将 gettext 与 PHP 和 poedit 一起使用。我写了以下 test.php 文件:
<?php
error_reporting(E_ALL | E_DEPRECATED | E_USER_DEPRECATED | -1);
bindtextdomain('messages', './i18n/');
textdomain('messages');
setlocale(LC_ALL, $_GET['l']);
putenv("LANG=".$_GET['l']);
echo _('test :-(');
?>
这是我的messages.po:
msgid ""
msgstr ""
"Project-Id-Version: Community Chess\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2011-10-07 18:34+0100\n"
"PO-Revision-Date: \n"
"Last-Translator: Martin Thom <info@martin-thoma.de>\n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"X-Poedit-SourceCharset: utf-8\n"
"X-Poedit-Basepath: /var/www/community-chess\n"
"X-Poedit-SearchPath-0: .\n"
#: test.php:8
msgid "test :-("
msgstr "Juhu :-)"
#~ msgid "test"
#~ msgstr "Juhu!"
我的目录结构是
community-chess
test.php
i18n
de_DE
LC_MESSAGES
messages.po
messages.mo
只要我查看http://localhost/community-chess/test.php?l=de_DE我就会得到“test :-(”
我已经生成了语言环境
sudo locale-gen de_DE
并检查
locale -a
为什么它不起作用?如何从 gettext 获得一些反馈?