4

I've installed zh_TW locale via

sudo locale-gen --purge en_US.UTF-8 zh_TW

And it codeset is BIG5

locale: zh_TW           directory: /usr/lib/locale/zh_TW
-------------------------------------------------------------------------------
    title | Chinese locale for Taiwan R.O.C.
    email | bug-glibc-locales@gnu.org
 language | Chinese
territory | Taiwan R.O.C.
 revision | 0.2
     date | 2000-08-02
  codeset | BIG5

And I've a simple PHP script

<?php

putenv('LC_ALL=zh_TW');
setlocale(LC_ALL, 'zh_TW');
bindtextdomain("myPHPApp", "./locale");
textdomain("myPHPApp");

echo gettext("hello");

I have prepared a mo file (which is in UTF8) and put under the

./locale/zh_TW/LC_MESSAGES/myPHPApp.mo 

And the echo did work, so, what is the point of installing locale such as zh_TW.UTF-8

Howard
  • 19,215
  • 35
  • 112
  • 184
  • There isn't any reason to `setlocale` if you've set it in your environment already, well, kind of. There are some categories that still need it if you use them: http://us2.php.net//manual/en/function.setlocale.php – l'L'l Jun 19 '14 at 05:18
  • What version of PHP you are using? – Capitaine Jun 27 '14 at 10:26

2 Answers2

2

What is the point of installing locale such as zh_TW.UTF-8?

The point of the .[codeset] suffix in locale specification is to specify a codeset. If, for a particular language, UTF-8 is a default codeset, you don't have to specify it explicitly - you are good with specifying just zh_TW (but you could also specify zh_TW.UTF-8). If you have console available, you can list the available locale by locale -a.

But please note that this can be system specific! While on linux zh_TW is UTF-8 by default, on IBM it will be BIG5 and on Windows CP950!

Tomas
  • 57,621
  • 49
  • 238
  • 373
  • Actually I am using Ubuntu, with `locale -a` I see zh_TW is BIG5, and the reason I ask is why I am using UTF8 in the mo file and it also work with the above code example. – Howard Jun 24 '14 at 16:21
  • 1
    @Howard it is strange inconsistency that `locale -a` says BIG5 and you say the files are for UTF-8. Anyway, you might be using both, as in this installation: https://answers.launchpad.net/ubuntu/+source/localeconf/+question/130696. – Tomas Jun 24 '14 at 19:01
  • no, `locale -a` say the installed locale is BIG5, but I say my mo file is UTF8 becoz it is prepared by me. My understanding is as my installed `zh_TW` is in BIG5, so when I use a UTF8 mo file, it should NOT work, but the thing is now it work, that is the confusing point. – Howard Jun 27 '14 at 09:37
2

According to my understanding for Chinese language, there is two different version for each of them which is simplified and traditional Chinese language. By specifying zh_TW probably is to display traditional Chinese characters on your webpage. Since UTF-8 is defined in your header and by default it supports both of the chinese language, hence it is not necessary to to install them anymore.

*Additional information - if I'm not mistaken, you got to set the Locale of zh_TW if the Chinese character are going to store somewhere in the database.

Hope this helps.

Eric T
  • 1,026
  • 3
  • 20
  • 42