Can't make (UTF-8) traditional Chinese character to work in PHP gettext extension (.po and .mo files created in poEdit)

为君一笑 提交于 2019-12-30 19:55:14

问题


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 <weedcl@hotmail.com>\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�@��!.


回答1:


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

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


来源:https://stackoverflow.com/questions/2264740/cant-make-utf-8-traditional-chinese-character-to-work-in-php-gettext-extensio

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!