Gettext没有在php中翻译文本

时间:2014-07-08 14:16:08

标签: php gettext

我不知道自己做错了什么。根据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>';
?>

我从该文件得到的结果是:

pputenv: 1

setlocale: da_DK.utf8

bindtextdomain: /var/www/sites/interna/Locale

bind_textdomain_codeset: UTF-8

textdomain: messages

gettext is supported 

HELLO_WORLD
Testing Translation...

最后,这是用于丹麦语翻译的.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"

有人可以帮忙吗?

1 个答案:

答案 0 :(得分:0)

所以我让它成功了,但我不确定我到底出错了。我注意到我错过了&#34; LC_MESSAGES&#34;我的丹麦文件的文件夹。哪个很傻:)

但是我还有一些其他的东西我调整了一点,好消息是它现在都有用了!