2010-02-14 85 views
3

我跟着folling教程:http://mel.melaxis.com/devblog/2005/08/06/localizing-php-web-sites-using-gettext/Php gettext不显示翻译后的文本(使用poEdit生成.pot和.mo文件后)!

关于PHP的gettext扩展(我未选中在php.ini评论)

了gettext被激活,但它并没有显示出来的翻译(德国)。

以下是文件:

C:\ WAMP \ WWW \ PHP测试\ test.php的:

<?php 
require_once("localization.php"); 
echo _("Hello World!"); 
?> 

C:\ WAMP \ WWW \ PHP测试\本地化.PHP:

<?php 
$locale = "de_DE"; 
if (isSet($_GET["locale"])) $locale = $_GET["locale"]; 
putenv("LC_ALL=$locale"); 
setlocale(LC_ALL, $locale); 
bindtextdomain("messages", "./locale"); 
textdomain("messages"); 
?> 

C:\瓦帕\ WWW \ PHP-测试\区域\ de_DE这个\ LC_MESSAGES \ messages.po:

msgid "" 
msgstr "" 
"Project-Id-Version: \n" 
"Report-Msgid-Bugs-To: \n" 
"POT-Creation-Date: 2010-02-14 00:35+0800\n" 
"PO-Revision-Date: 2010-02-14 00:37+0800\n" 
"Last-Translator: Jano Chen <[email protected]>\n" 
"Language-Team: \n" 
"MIME-Version: 1.0\n" 
"Content-Type: text/plain; charset=UTF-8\n" 
"Content-Transfer-Encoding: 8bit\n" 
"X-Poedit-KeywordsList: _;gettext;gettext_noop\n" 
"X-Poedit-Basepath: C:\\wamp\\www\\php-test\n" 
"X-Poedit-Language: German\n" 
"X-Poedit-Country: GERMANY\n" 
"X-Poedit-SourceCharset: iso-8859-1\n" 
"X-Poedit-SearchPath-0: .\n" 

#: test.php:2 
msgid "Hello World!" 
msgstr "Hallo Welt!" 

C:\ WAMP \ WWW \ PHP测试\区域\ de_DE这个\ LC_MESSAGES \ messages.mo

(对不起,因为某种原因,我不能复制该文件的文本)

alt text http://img202.imageshack.us/img202/8892/mofile.png

当我打开它应该显示“喂世界报”(世界您好在德国),而是它显示在英语(你好世界)。

有什么建议吗?

PS:我使用Windows XP SP2

回答

1

我正在使用Wamp Server 2(i),我卸载了它并使用了Wamp Server 2(c),并解决了问题。奇怪的。

+0

所有你需要做的就是重启Apache – 2017-10-05 13:03:58

0

如手册页statedsetlocale(?你读它),Windows使用不同language/country/region字符串。尝试将它们添加到您的de_DE,像这样(也from the man page):

setlocale(LC_ALL, 'de_DE', 'deu_deu'); 

还看到维持每个进程的区域设置信息的警告。

+0

它没有工作,我认为php setlocale是正确的。我检查了http://msdn.microsoft.com/en-us/library/dd318693%28VS.85%29.aspx和它的de_DE语言环境字符串。 – alexchenco 2010-02-15 07:36:14

0

有一点基本,我知道,但是您是否尝试重新启动Web服务器?每次更新我的.mo文件时,我都必须这样做。

0

提供给消息目录(bindtextdomain函数的第二个参数)的目录路径应该包含de_DE/LC_MESSAGES /,在这个目录中你必须复制你的mo文件。

0

所有你需要做的就是重启Apache。