Mar*_*oma 5 php gettext internationalization poedit
我目前正在尝试使用PHP和poedit的gettext.我写了以下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 :-(');
?>
Run Code Online (Sandbox Code Playgroud)
这是我的消息.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!"
Run Code Online (Sandbox Code Playgroud)
我的目录结构是
community-chess
test.php
i18n
de_DE
LC_MESSAGES
messages.po
messages.mo
Run Code Online (Sandbox Code Playgroud)
一看到http://localhost/community-chess/test.php?l = de_DE我就得到"test :-("
我已经生成了语言环境
sudo locale-gen de_DE
Run Code Online (Sandbox Code Playgroud)
并检查
locale -a
Run Code Online (Sandbox Code Playgroud)
为什么不起作用?我如何从gettext获得一些反馈?
这就是我在 Linux 上的 CE ZendServer 和 NetBsd 上的 Apache 服务器上的工作
\n\n文件“message.po”从应用程序的根目录生成:
\n\n#, fuzzy\nmsgid ""\nmsgstr ""\n"Project-Id-Version: PACKAGE VERSION\\n"\n"Report-Msgid-Bugs-To: \\n"\n"POT-Creation-Date: 2013-04-30 19:38+0200\\n"\n"PO-Revision-Date: 2013-04-12 14:00+0000\\n"\n"Last-Translator: gin(e) <ginex@posta.indivia.net>\\n"\n"Language-Team: LANGUAGE <LL@li.org>\\n"\n"Language: eo\\n"\n"MIME-Version: 1.0\\n"\n"Content-Type: text/plain; charset=utf-8\\n"\n"Content-Transfer-Encoding: 8bit\\n"\n\n#: include/apteryx_text.php:3\nmsgid "email:"\nmsgstr "Retpo\xc5\x9dtadreso:"\nRun Code Online (Sandbox Code Playgroud)\n\n这是新的树目录:
\n\nres/locale/\n de_DE/\n LC_MESSAGES/\n messages.mo\n eo_EO/\n LC_MESSAGES/\n messages.mo\n eo->eo_EO (symlink)\nRun Code Online (Sandbox Code Playgroud)\n\n我必须添加“eo”符号链接,因为我的系统上仅支持三种世界语语言环境:
\n\neo\neo.iso88593\neo.utf8\nRun Code Online (Sandbox Code Playgroud)\n\n编译惠特:
\n\nsudo locale-gen eo\nsudo locale-gen eo.iso88593\nsudo locale-gen eo.utf8\nsudo update-locale\nsudo dpkg-reconfigure locales\nRun Code Online (Sandbox Code Playgroud)\n\n目前我的 locale.php 代码是:
\n\n$charset="UTF-8";\n$gettext_domain="messages";\n$locale_dir="res/locale";\nputenv("LC_ALL=$lang");\n$l=split("_",$lang);\n/* not in all system and not all locales got the classic name this stupid method try to solve it*/\nif(! setlocale(LC_ALL, $lang.".".$charset)) \n if(! setlocale(LC_ALL, $lang)) \n if(! setlocale(LC_ALL,$l[0].".".$charset)) \n setlocale(LC_ALL,$l[0]);\n\nbindtextdomain($gettext_domain, "res/locale");\ntextdomain($gettext_domain);\nbind_textdomain_codeset($gettext_domain, $charset);\nRun Code Online (Sandbox Code Playgroud)\n\n因为如果没有它 gettext 就不起作用。我认为区域设置目录必须与 setlocale 设置的语言具有相同的名称。另一件事是测试每个函数调用什么返回。它们绝不能返回 NULL 或 FALSE。您可以通过简单的方式做到这一点:
\n\nvar_dump(bindtextdomain($gettext_domain, "res/locale"));\nvar_dump(textdomain($gettext_domain)); \n..and so on..\nRun Code Online (Sandbox Code Playgroud)\n\n最后但不是列表,请记住为所有 .mo 文件设置正确的 apache 权限,重新启动 apache 服务器并通过 phpinfo() 验证“GetText Support”是否已“启用”。
\n| 归档时间: |
|
| 查看次数: |
3162 次 |
| 最近记录: |