Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Gettext不工作,没有错误消息,使用PHP5.3_Php_Linux_Localization_Php 5.3_Gettext - Fatal编程技术网

Gettext不工作,没有错误消息,使用PHP5.3

Gettext不工作,没有错误消息,使用PHP5.3,php,linux,localization,php-5.3,gettext,Php,Linux,Localization,Php 5.3,Gettext,我这几天一直在这件事上胡思乱想,但都没有成功。我只是想让gettext开始工作 所发生的事情是打印php文件中写入的字符串,而不是翻译后的字符串。也就是说,如果我使用“echo gettext(“Service”);”则打印“Service”,而不是瑞典的“Tjänster” httpd/error\u日志中绝对没有错误消息。在运行应用程序或(重新)启动apache时不会 使用Centos 6.2和PHP5.3 这是我的目录结构: /path/to/locale/sv_SE.utf8/LC_ME

我这几天一直在这件事上胡思乱想,但都没有成功。我只是想让gettext开始工作

所发生的事情是打印php文件中写入的字符串,而不是翻译后的字符串。也就是说,如果我使用“echo gettext(“Service”);”则打印“Service”,而不是瑞典的“Tjänster”

httpd/error\u日志中绝对没有错误消息。在运行应用程序或(重新)启动apache时不会

使用Centos 6.2和PHP5.3

这是我的目录结构:

/path/to/locale/sv_SE.utf8/LC_MESSAGES/messages.mo
/path/to/setlocale.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");

?>
My 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 <LL@li.org>\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"

如果有人能提供帮助,那就太好了。我不知道如何继续,大多数帖子/线程都在讨论如何在使用PHP5.2时进行安装,而intl并不是其中的一部分。但我甚至不知道问题是否与系统设置或其他任何方面有关

不确定这是否能帮助您,但这段代码对我很有用

$lang_path = FCPATH.APPPATH.'language/locale';
putenv('LANG='.$code.'.UTF-8');
setlocale(LC_ALL, $code.'.UTF-8');
bindtextdomain('lang', $lang_path);
textdomain('lang');

不确定这是否能帮到你,但这段代码对我很有用

$lang_path = FCPATH.APPPATH.'language/locale';
putenv('LANG='.$code.'.UTF-8');
setlocale(LC_ALL, $code.'.UTF-8');
bindtextdomain('lang', $lang_path);
textdomain('lang');

这里也有同样的问题。什么样的图书馆没有错误信息(我有一个类似的问题,但我解决了它:这里有同样的问题。什么样的库没有错误消息?:(我有一个类似的问题,但我解决了它:如果您在控制台(PHP-CLI)而不是在Web服务器上测试gettext,您也必须重置语言环境变量。putenv(“LANGUAGE=”);如果您是在控制台(PHP-CLI)而不是在Web服务器上测试gettext,则还必须重置语言环境变量。putenv(“LANGUAGE=”);