php-gettext 不工作
我正在尝试使用 php-gettext 设置本地化,但无论如何它似乎都不起作用。
我有一个index.php:
<?php require_once "localization.php";?>
<a href="?locale=en_US">English</a> |
<a href="?locale=de_DE">German</a>
<br>
<?php echo _("Hello World!"); ?><br>
<?php echo _("My name is"); ?> Bob.
和localization.php
<?php $locale = false;
if (isset($_GET["locale"])) { $locale = $_GET["locale"];}
putenv("LC_ALL=$locale");
setlocale(LC_ALL, $locale);
bindtextdomain("messages", "./locale");
textdomain("messages");
我还在./locale/de_DE/LC_MESSAGES/messages.po / .mo下创建了翻译文件
我正在Ubuntu 11.04(natty),PHP版本5.3.5下尝试这个-1ubuntu7.3,apache2
有什么建议吗?
I'm trying to setup localization using php-gettext, but it doesn't seem to work no matter what.
I have an index.php:
<?php require_once "localization.php";?>
<a href="?locale=en_US">English</a> |
<a href="?locale=de_DE">German</a>
<br>
<?php echo _("Hello World!"); ?><br>
<?php echo _("My name is"); ?> Bob.
and the localization.php
<?php $locale = false;
if (isset($_GET["locale"])) { $locale = $_GET["locale"];}
putenv("LC_ALL=$locale");
setlocale(LC_ALL, $locale);
bindtextdomain("messages", "./locale");
textdomain("messages");
I also created the translation files under ./locale/de_DE/LC_MESSAGES/messages.po / .mo
I'm trying this under Ubuntu 11.04 (natty), PHP Version 5.3.5-1ubuntu7.3, apache2
Any suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试:
Try:
也许太晚了,但我遇到了同样的问题:
1st -You need to add
.utf8
to your$locale
string第二 - 如果未安装该语言,请使用
locale -a
检查您的系统是否支持该语言,例如 de_DE:sudo apt-get install language-pack-de-base
Maybe much too late, but I had the same problem:
1st -You need to add
.utf8
to your$locale
string2nd - check that your system supports the language using
locale -a
if not install the language e.g. de_DE:sudo apt-get install language-pack-de-base