Gettext示例在Windows 7上不起作用-XAMPP
我拥有PHP 5.6.8和启用了gettext的最新XAMPP(3.2.1).我正在尝试使用我在互联网上找到的示例来使gettext()在那里工作: https://github.com/leftnode/gettext-example ,但不起作用.
I have the latest XAMPP (3.2.1) with PHP 5.6.8 and gettext enabled. I'm trying to get gettext() working there using a sample I've found on the internet: https://github.com/leftnode/gettext-example , but it is not working.
我尝试过的其他代码(translation.php):
Other code I've tried (translation.php):
<?php
session_start();
$textdomain = "messages";
$lang = "de_DE";
echo(putenv("LC_ALL=".$lang)."<br>"); // outputs 1
setlocale(LC_ALL, $lang);
echo(bindtextdomain($textdomain, "locale")."<br>"); // successfully outputs the correct path to locale
textdomain($textdomain);
echo ((function_exists("_") && function_exists("gettext"))?"gettext loaded\n<br>":""); // outputs gettext loaded
$name = "Vic";
printf(_("Hello, %s, it is nice to see you today.\n"), $name); // outputs original english
?>
翻译文件-使用Poedit 1.8.1(messages.po)编译
translation files - compiled with Poedit 1.8.1 (messages.po)
# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR Codegroove.net
# This file is distributed under the same license as the PACKAGE package.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
msgid ""
msgstr ""
"Project-Id-Version: Codegroove.net Example Translations 0.0.1\n"
"Report-Msgid-Bugs-To: vmc@codegroove.net\n"
"POT-Creation-Date: 2015-06-01 11:34+0100\n"
"PO-Revision-Date: 2015-06-01 11:38+0100\n"
"Last-Translator: \n"
"Language-Team: \n"
"Language: de_DE\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"X-Generator: Poedit 1.8.1\n"
"X-Poedit-SourceCharset: UTF-8\n"
"X-Poedit-KeywordsList: _\n"
"X-Poedit-Basepath: ..\\..\\..\\\n"
"X-Poedit-SearchPath-0: .\n"
#: translation.php:15
msgid "Hello, %s, it is nice to see you today.\n"
msgstr "Hallo, %s, es ist schön dich zu sehen heute.\n"
文件位置
gettext\translation.php
gettext\locale\de_DE\LC_MESSAGES\messages.po
gettext\locale\de_DE\LC_MESSAGES\messages.mo
还有什么我可以尝试使gettext工作的?
What else can I try to make the gettext working?
我发现,尽管PHP报告确实没有正确设置语言环境. PHP中存在一个导致此错误的错误: https://bugs.php.net /bug.php?id=66265
I've found out that the locale is not set correctly although PHP reports it does. There is a bug in PHP that is causing this: https://bugs.php.net/bug.php?id=66265
因此,gettext始终使用系统默认语言环境进行翻译(使用我的系统语言环境创建翻译后,它实际上可以工作). 相关StackOverflow问题: Gettext将始终使用系统默认语言环境
As a result gettext always uses system default locale for translations (after creating translations with my system locale it actually works). Related StackOverflow question: Gettext will always use system default locale
尽管该错误已关闭,但在某种程度上应该可以正常工作,但我无法使其运行.
相反,我现在正在使用读取gettext .po文件并且可以正常工作的PHP解决方案:php-gettext
( https://launchpad.net/php-gettext )
Although the bug is closed and it should somewhat partially work I wasn't able to get it running.
Instead I'm now using PHP solution that reads gettext .po files and that works: php-gettext
(https://launchpad.net/php-gettext)