Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/258.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/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
Gettext不是在用php翻译文本_Php_Gettext - Fatal编程技术网

Gettext不是在用php翻译文本

Gettext不是在用php翻译文本,php,gettext,Php,Gettext,我不知道我做错了什么。根据phpinfo,Gettext已启用。我已经检查了系统使用的区域设置并生成了丹麦语言,因此系统中存在语言别名 我不知道我是否在下面显示的php文件中正确设置了内容: <?php // I18N support information here $language = "da_DK.utf8"; $p = putenv("LANG=" . $language); echo 'pputenv: '.$p; echo "<br>"; echo "<b

我不知道我做错了什么。根据phpinfo,Gettext已启用。我已经检查了系统使用的区域设置并生成了丹麦语言,因此系统中存在语言别名

我不知道我是否在下面显示的php文件中正确设置了内容:

<?php
// I18N support information here
$language = "da_DK.utf8";

$p = putenv("LANG=" . $language);
echo 'pputenv: '.$p;
echo "<br>";
echo "<br>";


$s = setlocale(LC_ALL, $language);
echo 'setlocale: '.$s;
echo "<br>";
echo "<br>";


// Set the text domain as "messages"
$domain = "messages";

$b = bindtextdomain($domain, "Locale");
echo 'bindtextdomain: '.$b;
echo "<br>";
echo "<br>";

$b2 = bind_textdomain_codeset($domain, 'UTF-8');
echo 'bind_textdomain_codeset: '.$b2;
echo "<br>";
echo "<br>";

$t = textdomain($domain);
echo 'textdomain: '.$t;
echo "<br>";
echo "<br>";

if (!function_exists("gettext"))
{
    echo "gettext is not installed\n";
}
else
{
    echo "gettext is supported\n";
}

echo "<br><br>";

//phpinfo();


echo _("HELLO_WORLD").'<br>';
echo _('Testing Translation...').'<br>';
?>
最后,这是用于丹麦语翻译的.po文件:

msgid ""
msgstr ""
"Project-Id-Version: danish interna\n"
"POT-Creation-Date: 2014-07-08 15:32+0100\n"
"PO-Revision-Date: 2014-07-08 15:32+0100\n"
"Last-Translator: \n"
"Language-Team: \n"
"Language: Danish\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"X-Generator: Poedit 1.5.4\n"
"X-Poedit-KeywordsList: _;gettext;gettext_noop\n"
"X-Poedit-Basepath: .\n"
"X-Poedit-SourceCharset: UTF-8\n"
"X-Poedit-SearchPath-0: ../..\n"

#: ../../index.php:49
msgid "HELLO_WORLD"
msgstr "Hej verden"

#: ../../index.php:50
msgid "Testing Translation..."
msgstr "Tester"

有人能帮忙吗?

所以我成功了,但我不确定我到底哪里出了问题。我注意到我丢失了丹麦文件的LC_MESSAGES文件夹。这很愚蠢:


但我还做了一些其他的调整,好消息是现在一切都正常了

您是否已将.po文件编译为/var/www/sites/interna/Locale/da_DK/LC_MESSAGES/MESSAGES.mo?是的。好我使用Poedit,它会自动执行。
msgid ""
msgstr ""
"Project-Id-Version: danish interna\n"
"POT-Creation-Date: 2014-07-08 15:32+0100\n"
"PO-Revision-Date: 2014-07-08 15:32+0100\n"
"Last-Translator: \n"
"Language-Team: \n"
"Language: Danish\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"X-Generator: Poedit 1.5.4\n"
"X-Poedit-KeywordsList: _;gettext;gettext_noop\n"
"X-Poedit-Basepath: .\n"
"X-Poedit-SourceCharset: UTF-8\n"
"X-Poedit-SearchPath-0: ../..\n"

#: ../../index.php:49
msgid "HELLO_WORLD"
msgstr "Hej verden"

#: ../../index.php:50
msgid "Testing Translation..."
msgstr "Tester"