我试图在本地服务器上运行gettext的基本设置。
我已经安装了它,当我运行phpinfo()时我可以看到它。
我的测试php文件是:
<?php
$language = 'fr';
putenv("LANG=$language");
setlocale(LC_ALL, $language);
// Set the text domain as 'messages'
$domain = 'messages';
bindtextdomain($domain, "/Tom/Web/locale/");
textdomain($domain);
echo gettext("A string to be translated would go here");
?>
在/Tom/Web/locale
我有两个文件夹en
和fr
(此网站根目录是/ Tom / Web /)
在每个文件夹中我都有LC_MESSAGES
,其中我有message.po&amp; messages.mo
在fr / LC_MESSAGES的message.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: TestProject\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2017-09-18 11:41+0100\n"
"PO-Revision-Date: 2017-09-18 12:02+0100\n"
"Language: fr\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n > 1);\n"
"Last-Translator: \n"
"Language-Team: \n"
"X-Generator: Poedit 2.0.3\n"
"X-Poedit-SourceCharset: UTF-8\n"
#: test.php:12
msgid "A string to be translated would go here"
msgstr "Une chaîne à traduire irait ici"
然而,当我在浏览器中打开tstp.php页面时,我得到的是英文文本而不是法文。
我做错了什么?
感谢。
答案 0 :(得分:1)
语言和目录应为fr_FR。自从我使用gettext()以来已经很长时间了,但我认为你已经指定了国家和语言。 (例如en_GB和en_US是不同版本的英语)