+ -
当前位置:首页 → 问答吧 → 关于gettext的代码问题

关于gettext的代码问题

时间:2008-07-10

来源:互联网

locale下 zh_CN/LC_MESSAGES/test.po test.mo 都在
但是始终不出现中文,感觉是找不到mo 和po文件

bindtextdomain 尝试用 locale ../locale 也都一样。

环境 ubuntu

php 代码如下

<?php
define('PACKAGE','test');
putenv('LANG=zh_CN');
setlocale(LC_ALL,'zh_CN');
bindtextdomain(PACKAGE,'/home/hatoyu/www/locale');
textdomain(PACKAGE);
echo gettext("ok");
echo gettext("ok2");


echo gettext("hello world");
echo gettext("who are u");
?>

po代码如下:

# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the PACKAGE package.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
msgid ""
msgstr ""
"Project-Id-Version: macaucs\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2008-07-10 11:48+0800\n"
"PO-Revision-Date: 2008-07-10 11:52+0800\n"
"Last-Translator: Hato Yu <[email protected]>\n"
"Language-Team: hatoyu <[email protected]>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
"X-Poedit-Language: Chinese\n"
"X-Poedit-Country: CHINA\n"
"X-Poedit-SourceCharset: utf-8\n"

#: /home/hatoyu/www/test.php:12
msgid "ok"
msgstr "好了"

#: /home/hatoyu/www/test.php:13
msgid "ok2"
msgstr "更好了"

#: /home/hatoyu/www/test.php:15
msgid "hello world"
msgstr "你好世界"

#: /home/hatoyu/www/test.php:16
msgid "who are u"
msgstr "你是谁"

作者: hatoyu   发布时间: 2008-07-10

解决问题还是要靠自己

setlocale(LC_ALL,'zh_CN.UTF-8');

后面加了utf-8 就解决了

我的os是 ubuntu 8.04 中文,估计和这个有关系

作者: hatoyu   发布时间: 2008-07-10

还是很聪明的读者

作者: phpcast   发布时间: 2008-07-15