无法使(UTF-8)繁体中文字符在 PHP gettext 扩展中工作(在 poEdit 中创建的 .po 和 .mo 文件)

发布于 2024-08-21 18:01:44 字数 1176 浏览 11 评论 0原文

我检查了 MSDN ,区域设置字符串是 zh_Hant,但我也尝试了 zh_TW(中文,台湾) 。

繁体中文字符在 poEditor 中看起来不错,但当我在浏览器中打开文件时,这些字符只是奇怪的符号(«∩o¥@∇É!)。我认为翻译是有效的,但编码有问题(我对字符集和源代码字符集都使用UTF-8)。

使用 poEditor 生成的文件:

messages.po:

msgid ""
msgstr ""
"Project-Id-Version: \n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2010-02-15 16:26+0800\n"
"PO-Revision-Date: 2010-02-15 16:26+0800\n"
"Last-Translator: Jano Chen <[email protected]>\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:\\wamp\\www\\php-test\n"
"X-Poedit-Language: Chinese\n"
"X-Poedit-Country: TAIWAN\n"
"X-Poedit-SourceCharset: utf-8\n"
"X-Poedit-SearchPath-0: .\n"

#: test.php:3
msgid "Hello World!"
msgstr "哈囉世界!"

PS:当我将 Firefox 中的编码显示更改为 Big5 时,字符会正确显示,但如果我将它们更改为 UTF-8,则会显示: ���o�@��!.

I checked MSDN and the locale string is zh_Hant, but I also tried with zh_TW (Chinese, Taiwan).

The traditional Chinese characters look OK in the poEditor, but when I open the file in the browser the characters are just weird symbols («¢Åo¥@¬É!). I think the translation is working, but there's something wrong with the encoding (I used UTF-8 for both Charset and Source Code Charset).

The files generated with poEditor:

messages.po:

msgid ""
msgstr ""
"Project-Id-Version: \n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2010-02-15 16:26+0800\n"
"PO-Revision-Date: 2010-02-15 16:26+0800\n"
"Last-Translator: Jano Chen <[email protected]>\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:\\wamp\\www\\php-test\n"
"X-Poedit-Language: Chinese\n"
"X-Poedit-Country: TAIWAN\n"
"X-Poedit-SourceCharset: utf-8\n"
"X-Poedit-SearchPath-0: .\n"

#: test.php:3
msgid "Hello World!"
msgstr "哈囉世界!"

PS: When I change the encoding display in Firefox to Big5 the characters are shown properly, but if I change them to UTF-8 it shows: ���o�@��!.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

兮颜 2024-08-28 18:01:44

我终于解决了。我必须将以下内容写入 localization.php 文件。

bind_textdomain_codeset("messages", 'UTF-8');

I finally solved it. I had to have the following to file localization.php.

bind_textdomain_codeset("messages", 'UTF-8');
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文