I'm already localized a website from Russian to English with PHP and gettext just with wrapping all strings into __($string)
function.
It works.
Here's the gists: https://gist.github.com/Grawl/ba8f39b8398791c6a67e
But it don't work with Chinese translation. I just added compiled .mo
(and source .po
) into locale/zh_CN/LC_MESSAGES/
, visit /index.php?locale=zh_CN
and don't see it translated at all.
What it wrong with Chinese?
Have I to use other language code or something?
I use zh_CN
to map on Chinese like it done in WordPress.
I cannot understand why.
Update:
The problem was in HTML <meta>
tag and charset going from server in Windows-1251
. Chop russian PHP server.
After I set <meta charset="GBK">
and turned off AddDefaultCharset
in .htaccess
, Chinese localization finally started to work.
After all, I added these modifications:
.htaccess
:
- AddDefaultCharset UTF-8
+ AddDefaultCharset off
+ RewriteRule ^cn index.php?locale=zh_CN&charset=GBK [L]
functions.php
, included before <!DOCTYPE html>
:
+ $charset=$_GET["charset"];
+ if(!isset($charset)) {
+ $charset="UTF-8";
+ }
head.php
, the <head>
tag content:
+ <meta charset="<?=$charset?>">
So, if I does not set charset into get request, it becomes UTF-8, otherwise it goes from get request. For Chiense I set it to GBK
, like on Taobao.com, and browser sets up right charset.
But after all I just has cyrillic characters encoded in Chinese glyphs, character by character.
Like this: Сервис и услуги
Becomes this: 褋械褉胁懈褋 懈 褍褋谢褍谐懈
If you paste these Chinese characters into decoder app, chose GB2312 on left (one from Chinese charsets) and UTF-8 on right, you will have ?е?ви? и ??л?ги
– some cyrillic characters corrupted but this is obviously an original string, because in translation I have more shorten 服务
for this phrase.
Help me please.
Update 2
I just forgot to set bind_textdomain_codeset();
to $domain
, it was messages
.
All works on unicode charset. All normal.
setlocale
call to work, which gettext depends on, yes. – Propertius