PHP`gettext`在Ubuntu中不起作用

时间:2013-11-24 00:01:33

标签: php internationalization gettext php-gettext

我正在尝试使用PHP get text为我的网站添加多语言支持。到目前为止不成功,我不明白为什么。

在我的i18n.php文件中,我有这个:

<?php

$locale = 'pt_PT.utf8';
$locale_dir = './locale';
$domain = 'messages';

setlocale(LC_ALL, $locale);
putenv("LANG=$locale");
putenv("LANGUAGE=$locale");
bindtextdomain($domain, $locale_dir);
bind_textdomain_codeset($domain, 'UTF-8');
textdomain($domain);

?>

然后,在./locale/pt_PT.utf8/LC_MESSAGES/messages.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.
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2013-11-23 20:31+0000\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"Language: pt_PT.utf8\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"

#: index.php:12
msgid "E-mail"
msgstr "Endereço electrónico"

#: index.php:13
msgid "Password"
msgstr "Palavra-chave"

#: index.php:14
msgid "Password (again)"
msgstr "Palavra-chave (novamente)"

#: index.php:15
msgid "Login"
msgstr "Entrar"

然后我生成.mo文件:

msgfmt -o ./locale/pt_PT.utf8/LC_MESSAGES/messages.mo ./locale/pt_PT.utf8/LC_MESSAGES/messages.po

似乎php要求locales安装在linux系统中,所以我检查了locale -a

C
C.UTF-8
de_AT.utf8
...
en_AG
...
es_AR.utf8
...
POSIX
pt_BR.utf8
pt_PT.utf8
...

i18n.php是我在index.php文件中的第一个包含,但没有消息显示。知道我错过了什么吗?

0 个答案:

没有答案