简体   繁体   English

PHP gettext-需要基本帮助

[英]PHP gettext - basic help needed

I'm trying to get a very basic setup of gettext working on my local server. 我正在尝试在本地服务器上进行gettext的非常基本的设置。

I've installed it and I can see it available when I run phpinfo(). 我已经安装了它,当我运行phpinfo()时可以看到它可用。

My test php file is: 我的测试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");
?>

In /Tom/Web/locale I have two folders en and fr /Tom/Web/locale我有两个文件夹enfr

(this web root is /Tom/Web/) (此Web根目录是/ Tom / Web /)

Within each of those folders I have LC_MESSAGES and within that I have messages.po & messages.mo 在这些文件夹中的每个文件夹中,我都有LC_MESSAGES而在其中,我具有messages.po&messages.mo

Within the message.po file in fr/LC_MESSAGES I have : 在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"

Yet when I open the tstp.php page in my browser I get the english text not the French. 但是,当我在浏览器中打开tstp.php页面时,得到的是英文文本而不是法语。

What have I done wrong ? 我做错了什么?

Thanks. 谢谢。

The language and directory should be fr_FR. 语言和目录应为fr_FR。 It's a long time since I used gettext(), but I think you have the specify the country and language. 自从我使用gettext()已有很长时间了,但是我认为您已经指定了国家/地区和语言。 (eg en_GB and en_US are different versions of English) (例如,en_GB和en_US是英语的不同版本)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM