Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sql-server-2005/2.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
PHP中的Gettext要求调用setlocale(LC_MESSAGES,NULL)_Php_Gettext_Setlocale_Php Gettext - Fatal编程技术网

PHP中的Gettext要求调用setlocale(LC_MESSAGES,NULL)

PHP中的Gettext要求调用setlocale(LC_MESSAGES,NULL),php,gettext,setlocale,php-gettext,Php,Gettext,Setlocale,Php Gettext,在Ubuntu上使用PHP5.5.9时,gettext无法正常工作,尽管所有设置都正确。 我用于设置gettext的行如下所示: putenv('LANG=es_ES.utf8'); setlocale(LC_MESSAGES, 'es_ES'); bindtextdomain('messages', './i18n'); bind_textdomain_codeset('messages', 'UTF-8'); textdomain('messages'); 这应该包含所需的一切。但是get

在Ubuntu上使用PHP5.5.9时,gettext无法正常工作,尽管所有设置都正确。

我用于设置gettext的行如下所示:

putenv('LANG=es_ES.utf8');
setlocale(LC_MESSAGES, 'es_ES');
bindtextdomain('messages', './i18n');
bind_textdomain_codeset('messages', 'UTF-8');
textdomain('messages');
这应该包含所需的一切。但是gettext总是返回默认语言环境的字符串(传入的字符串),而不是正确的翻译

调用
locale-a
也会列出所需的所有语言,因此这也是正确设置的

phpinfo()
证明gettext(以及
intl
扩展)安装正确:

GetText Support = enabled
intl version = 1.1.0
ICU version = 52.1
ICU Data version = 52.1
当然,Ubuntu已经重新启动了

最后,指定的目录也包含gettext所需的翻译文件

简言之,一切似乎都设置正确——但不起作用

但是,当我添加
setlocale(LC_消息,NULL)时setlocale(LC_消息'es_-es')之前的code>,gettext突然起作用。

有人能解释一下吗?虽然OS和PHP版本不再是最新版本,但我不知道有什么bug会阻止gettext在这个堆栈上工作

这个解决方案感觉像是一个肮脏的黑客,我当然不喜欢依赖它。

当您调用setlocale(LC_MESSAGES,NULL)时,它使用环境中的区域名称,因此它将是“es_es.utf8”

您可以尝试调用setlocale(LC_消息,“es_es.utf8”),甚至更好

setlocale(LC\u消息,数组(“es\u es”,“es\u es.utf8”))谢谢,就这样!另一个系统有所有三个地区
es_es
es_es.iso88591
es_es.utf8
,因此它在那里工作。我想,
.utf8
版本是最常见的版本吧?