0

我使用 Poedit(在 Win7 上运行)生成 .mo/.po 文件,以使用 PHP gettext 制作俄语版本的网页。当我显示页面的俄语版本时,所有字符都显示为黑色菱形/正方形。

这是一个演示该问题的示例网页:

http://cthorn.co.uk/localization/index.php

...这是俄语版本:

http://cthorn.co.uk/localization/index.php?locale=ru_RU

的代码index.php是:

<?php require_once("locale/localization.php"); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    <head>
        <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
        <title>Test</title>
    </head>

    <body>
        <p><? echo _("This is the text to be translated."); ?></p>
    </body>
</html>

该文件的代码localization.php是:

<?php
    $locale = "en_GB";
    if (isSet($_GET["locale"])) $locale = $_GET["locale"];
    putenv("LC_ALL=$locale");
    setlocale(LC_ALL, $locale);
    bindtextdomain("messages", "./locale");
    textdomain("messages");
?>

目录结构为:

 - localization
    - locale
       - ru_RU
          - LC_MESSAGES
               messages.mo
               messages.po
         localization.php
      index.php

在 Poedit 中,我将“字符集”和“源代码字符集”都设置为UTF-8. “语言”设置为Russian,“国家/地区”设置为RUSSIAN FEDERATION

在粘贴到 Poedit 之前,我确保从 UTF-8 编码的文本文件中复制了俄语文本。

我错过了什么?

这里是messages.po从 Notepad++ 中复制出来的:

msgid ""
msgstr ""
"Project-Id-Version: \n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2011-11-16 10:49-0000\n"
"PO-Revision-Date: 2011-11-16 10:49-0000\n"
"Last-Translator: \n"
"Language-Team: \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: C:\\websites\\cthorn.co.uk\\live\n"
"X-Poedit-Language: Russian\n"
"X-Poedit-Country: RUSSIAN FEDERATION\n"
"X-Poedit-SourceCharset: utf-8\n"
"X-Poedit-SearchPath-0: .\n"

#: localization/index.php:10
msgid "This is the text to be translated."
msgstr "Это текст для перевода."

啊抱歉 - 从以下位置下载文件:

cthorn(dot)co(dot)uk/localization/locale/ru_RU/LC_MESSAGES/messages.mo cthorn(dot)co(dot)uk/localization/locale/ru_RU/LC_MESSAGES/messages.po

(我只能发布两个链接,因为我是 n00b)

4

2 回答 2

1

好吧,您页面上的俄语文本是 ISO-8859-5。问题是它是如何以这种编码结束的 :) 你能显示你的 .po 文件吗?

UPD。您文件中的所有内容看起来都很好。我唯一能想到的就是试试这个:

    setlocale(LC_ALL, $locale.'.utf8');
    bind_textdomain_codeset("messages", 'UTF-8');
于 2011-11-16T11:16:54.100 回答
1

确保一切都在 utf-8 中,它会很好用。

不同的内容编码总是最终成为a**中的真正痛苦

于 2011-11-16T11:25:25.953 回答