[英]PHP gettext - basic help needed
我正在尝试在本地服务器上进行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
(此Web根目录是/ Tom / Web /)
在这些文件夹中的每个文件夹中,我都有LC_MESSAGES
而在其中,我具有messages.po&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页面时,得到的是英文文本而不是法语。
我做错了什么?
谢谢。
语言和目录应为fr_FR。 自从我使用gettext()已有很长时间了,但是我认为您已经指定了国家/地区和语言。 (例如,en_GB和en_US是英语的不同版本)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.