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

1

5

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�@��!.

Nonie answered 15/2, 2010 at 8:36 Comment(0)
N
11

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

bind_textdomain_codeset("messages", 'UTF-8');
Nonie answered 16/2, 2010 at 16:15 Comment(1)
I was working on this for hours. Thank you!! For anyone having this issue, the first param of bind_textdomain_codeset() should be set to whatever you set with textdomain(). If you used textdomain('messages') then you would use the code in alexchenco's example above.Crosscheck

© 2022 - 2024 — McMap. All rights reserved.