我使用 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)