【发布时间】:2019-01-18 10:20:07
【问题描述】:
我正在尝试在运行 PHP 7.1 的 CentOS 服务器上设置 PHP 国际化
这是我的目录结构:
/home/project/public_html/locale/japanese/LC_MESSAGES/messages.po
/home/project/public_html/locale/japanese/LC_MESSAGES/messages.mo
/home/project/public_html/index.php
messages.po 包含该行(以及其他):
"Language: japanese\n"
"Content-Type: text/plain; charset=UTF-8\n"
我有以下代码:
$check_putenv = putenv("LC_ALL=japanese");
if (!$check_putenv) {
echo "Warning: putenv LC_ALL failed!\n";
}
$check_putenv2 = putenv("LANGUAGE=japanese");
if (!$check_putenv2) {
echo "Warning: putenv LANGUAGE failed!\n";
}
$check_locale = setlocale(LC_MESSAGES, 'japanese');
if (!$check_locale) {
echo "Warning: Failed to set locale japanese!\n";
}
$check_bind = bindtextdomain("messages", "/home/project/public_html/locale");
if (!$check_bind) {
echo "Warning: Failed to bind text domain!\n";
}
$check_textdomain = textdomain("messages");
if ($check_textdomain !== "messages") {
echo "Warning: Failed to set text domain!\n";
}
输出是
Warning: Failed to bind text domain!
locale -a 返回(等等)
ja_JP
ja_JP.utf8
japanese
知道可能出了什么问题吗?
【问题讨论】:
-
您是否尝试过
$lang = 'ja_JP'或ja_JP.UTF-8(并在所有设置和目录名称中使用此变量)? -
您是否通过存储库管理在您的系统上安装了日语语言包?之后重新配置(创建)语言环境?
-
如编辑所示,即使系统上安装了“japanese”别名,我也不确定gettext的PHP实现是否接受这个。
-
谢谢,ja_JP.UTF-8 有效!
标签: php internationalization gettext