PHP setlocale,UTF-8与否?
作者:互联网
我通过安装了zh_TW语言环境
sudo locale-gen --purge en_US.UTF-8 zh_TW
它的代码集是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
我有一个简单的PHP脚本
<?php
putenv('LC_ALL=zh_TW');
setlocale(LC_ALL, 'zh_TW');
bindtextdomain("myPHPApp", "./locale");
textdomain("myPHPApp");
echo gettext("hello");
我准备了一个mo文件(以UTF8格式)并放在
./locale/zh_TW/LC_MESSAGES/myPHPApp.mo
回声确实有效,因此,安装区域设置有什么意义,例如zh_TW.UTF-8
解决方法:
What is the point of installing locale such as zh_TW.UTF-8?
区域设置规范中.[codeset]后缀的要点是指定代码集.如果对于特定语言,UTF-8是默认代码集,则不必明确指定它 – 您只需指定zh_TW(但您也可以指定zh_TW.UTF-8).如果您有可用的控制台,则可以按locale -a列出可用的区域设置.
但请注意,这可能是系统特定的!而on linux zh_TW is UTF-8 by default,on
IBM it will be BIG5和Windows CP950!
标签:php,localization,internationalization,locale,setlocale 来源: https://codeday.me/bug/20190624/1278376.html