doudandui1592 2013-12-21 15:35
浏览 51
已采纳

PHP gettext简体中文支持?

I'm trying to support traditional chinese in one of my PHP projects, but I can't get it to show any chinese characters. Here's my gettext setup:

putenv("LC_ALL=zh_CN.utf8");
setlocale(LC_ALL, "zh_CN.utf8");
bindtextdomain("wpsmessages", dirname(__FILE__) . "/locale");
bind_textdomain_codeset("wpsmessages", 'UTF-8');
textdomain("wpsmessages");

Earlier I created the locale in SSH by typing:

sudo locale-gen zh_CN.utf8

Which then returned:

Generating locales...
zh_CN.UTF-8... done

After typing locale -a I get the follwing in the list (among others):

zh_CN
zh_CN.utf8

But still, it doesn't show any chinese characters. What am I doing wrong here?

  • 写回答

1条回答 默认 最新

  • dqc42632 2013-12-21 16:20
    关注

    A little emberrassing, but the solution was simply renaming the file wpsmessages-zh_CN.mo to wpsmessages.mo following my own file name conventions.

    Basically the structure of my PHP project using gettext is like this:

    /locale/pt_BR.utf8/LC_MESSAGES/wpsmessages.mo
    /locale/zh_CN.utf8/LC_MESSAGES/wpsmessages.mo
    ...
    

    So using bindtextdomain("wpsmessages", dirname(__FILE__) . "/locale"); gets the correct .mo file for a locale specified by setlocale(), but it couldn't find the file as it's name was wrong.

    Hope this helps anyone being as stupid as me. :)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化