我已经在这件事上摸索了好几天了,但没有成功。我只是想让 gettext 工作。
发生的情况是打印 php 文件中写入的字符串,而不是翻译后的字符串。 IE。如果我做“echo gettext(“Service”);”然后打印“Service”,而不是瑞典语“Tjänster”。
httpd/error_log 中绝对没有错误消息。运行应用程序或(重新)启动 apache 时不会。
使用 Centos 6.2 和 php 5.3。
这是我的目录结构:
/path/to/locale/sv_SE.utf8/LC_MESSAGES/messages.mo
/path/to/setlocale.php
我的 messages.po 文件:
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2012-01-18 20:09+0100\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <[email protected] /cdn-cgi/l/email-protection>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
#: setlocale.php:29
msgid "Service"
msgstr "Tjänst"
#: setlocale.php:30
msgid "Name"
msgstr "Tjänst"
设置语言环境.php:
<?php
if (!function_exists("gettext"))
{
echo "gettext is not installed";
}
else
{
echo "gettext is supported";
}
echo "Exist?: ".setlocale(LC_MESSAGES, 'sv_SE.utf8')."; //Prints 'sv_SE.utf8, hence it exist in the system.
bindtextdomain('messages', '/var/www/html/smic/modules/core/localization/locale');
textdomain('messages');
bind_textdomain_codeset('messages', 'UTF-8');
echo gettext("Service");
echo _("Name");
?>
由于打印了“支持 gettext”,因此 gettext 至少在某种程度上起作用了。
'sv_SE.utf8' 也被打印出来,因此它存在于系统中
我已经尽我所能来安装正确的软件包(嗯,至少根据我的理解,但当然这里可能存在一些问题)。 PHP 5.3 将 intl 作为核心的一部分。我还没有成功地使用 ./configure --enable-intl 进行编译。我在尝试使用它时确实遇到了错误,我猜这是因为它是 php 5.3 的一部分。我对吗?
我找不到任何 intl.so (updatedb 已完成并搜索它)来添加到 php.ini 文件中,也没有添加 extension=intl.so 。我也这样做了,但没有成功,但如果我找不到 intl.so 我想添加 extension=intl.so 是没有意义的?
有些线程提到了一些要安装的软件包,我也尝试过:
yum install libicu-devel
yum install libicu
如果有人可以提供帮助,那就太好了,我不知道如何继续前进,大多数帖子/线程都在讨论如何在使用 PHP 5.2 时安装,其中 intl 不属于其中。但我什至不知道问题是否与系统设置有关或其他什么问题。