我使用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中,我将“Charset”和“Source code charset”都设置为UTF-8
。 “语言”设置为Russian
,“国家/地区”设置为RUSSIAN FEDERATION
。
我确保俄语文本是在被粘贴到Poedit之前从UTF-8编码的文本文件中复制的。
我错过了什么?
这是从{Notepad ++:
复制的messages.po
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(点)共(点)英国/定位/区域/ ru_RU / LC_MESSAGES / messages.mo cthorn(点)共(点)英国/定位/区域/ ru_RU / LC_MESSAGES / messages.po
(我只能发布两个链接,因为我是n00b)
答案 0 :(得分:1)
嗯,您网页上的俄语文字是ISO-8859-5。问题是它是如何以编码结束的:) 你能展示你的.po文件吗?
UPD。 文件中的所有内容都很好。我唯一能想到的就是试试这个:
setlocale(LC_ALL, $locale.'.utf8');
bind_textdomain_codeset("messages", 'UTF-8');
答案 1 :(得分:1)
确保所有内容都在utf-8中,并且效果很好。
不同的内容编码总是最终成为a **
中的真正痛苦