2

我一直在尝试使用以下代码使用 Poedit 和 PHP 进行翻译。这是一个非常基本的示例,我正在尝试将其翻译成德语。我在以下文件夹中有文件。

/home/test/test.php
/home/test/localization.php
/home/test/locale/de_DE/LC_MESSAGES/default.po
/home/test/locale/de_DE/LC_MESSAGES/default.mo

测试.php

require_once("localization.php");
echo _("Hello World!");

本地化.php

$locale = "de_DE";

if (isset($_GET["locale"])) 
    $locale = $_GET["locale"];

putenv("LC_ALL=$locale");

setlocale(LC_ALL, $locale);

bindtextdomain("default", "./locale");

textdomain("default");

当我运行时localhost:8080/test/test.php,它只显示英文消息"Hello World!"。我已经翻译了default.po。这里是:

msgid ""
msgstr ""
"Project-Id-Version: a\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2014-01-29 09:37+0530\n"
"PO-Revision-Date: 2014-01-29 09:38+0530\n"
"Last-Translator: Rahul <rahul@gmail.com>\n"
"Language-Team: b <a@b.com>\n"
"Language: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"X-Poedit-KeywordsList: _;gettext;gettext_noop\n"
"X-Poedit-Basepath: .\n"
"X-Poedit-Language: German\n"
"X-Poedit-Country: GERMANY\n"
"X-Poedit-SourceCharset: UTF-8\n"
"X-Poedit-SearchPath-0: .\n"

#: test.php:4
msgid "Hello World!"
msgstr "Hallo Welt!"

有什么想法我哪里出错了吗?提前致谢。

4

0 回答 0