php-gettext无法正常工作 [英] php-gettext isn't working

查看:118
本文介绍了php-gettext无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用php-gettext设置本地化,但是无论如何它似乎都不起作用.

I'm trying to setup localization using php-gettext, but it doesn't seem to work no matter what.

我有一个index.php:

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.

和localization.php

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");

我还在./locale/de_DE/LC_MESSAGES/messages.po/.mo

I also created the translation files under ./locale/de_DE/LC_MESSAGES/messages.po / .mo

我正在Ubuntu 11.04(natty),PHP版本5.3.5-1ubuntu7.3,apache2下尝试此操作

I'm trying this under Ubuntu 11.04 (natty), PHP Version 5.3.5-1ubuntu7.3, apache2

有什么建议吗?

推荐答案

尝试:

<?php
$directory = dirname(__FILE__).'/locale';
$domain = 'messages';
$locale ="your_locale"; //like pt_BR.utf8";

putenv("LANG=".$locale); //not needed for my tests, but people say it's useful for windows

setlocale( LC_MESSAGES, $locale);
bindtextdomain($domain, $directory);
textdomain($domain);
bind_textdomain_codeset($domain, 'UTF-8');
?>

这篇关于php-gettext无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆