【发布时间】:2015-06-01 09:53:53
【问题描述】:
我有最新的 XAMPP (3.2.1) 并启用了 PHP 5.6.8 和 gettext。我正在尝试使用我在互联网上找到的示例让 gettext() 在那里工作:https://github.com/leftnode/gettext-example,但它不起作用。
我尝试过的其他代码(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) 编译
# 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 正常工作?
【问题讨论】:
标签: php localization gettext