我的环境:ubuntu server +xampp 套件php代码中的输出是使用简体中文来输出的,现在 要将简体中文的输出转换成英文,和繁体中文。
使用gettext 来做。现象 : 无法转换!
        但是, 如果吧代码中得中文换成英文字符,然后在 .po文件中更新一下,再生成.mo文件后,则能够正常转换!
也就是说 当po文件中的需要转换的字符串为中文的时候 则不能转!即  中文 --》 其他语言 ,不成功!
    英文 --》 其他语言 ,则能够成功!!
请大家来讨论下这是为什么?!

解决方案 »

  1.   

    下载地址:
    http://sourceforge.net/projects/gnuwin32/files/gettext/0.14.4/gettext-0.14.4-src.zip/download第一步:撰写PHP程序
    <?php
    putenv("LANG=zh_CN");
    setlocale(LC_ALL, "zh_CN");bindtextdomain("test", "./locale");
    textdomain("test");echo gettext("Hello!");
    echo gettext("World!");
    echo gettext("Hello World!");
    ?>
    第二步:
    xgettext.exe -d test -L PHP --from-code=utf-8 index.php第三步:
    修改test.po为:#: ../index.php:8
    msgid "Hello!"
    msgstr "你好!"#: ../index.php:9
    msgid "World!"
    msgstr "世界!"#: ../index.php:10
    msgid "Hello World!"
    msgstr "你好,世界!"第四步:
    msgfmt -o zh_CN/test.mo zh_CN/test.po
    生成test.mo文件
    第五步:
    创建locale\zh_CN\LC_MESSAGES目录,将test.mo放入该目录中
    第六步:
    重启apache,访问index.php即可看到效果
      

  2.   

    我是直接在linux下编辑的 页面编码、字符编码已经都是utf-8了