php-gettext 不工作

发布于 2024-12-19 14:34:28 字数 745 浏览 4 评论 0原文

我正在尝试使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

记忆里有你的影子 2024-12-26 14:34:28

尝试:

<?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');
?>

Try:

<?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');
?>
孤独岁月 2024-12-26 14:34:28

也许太晚了,但我遇到了同样的问题:

1st -You need to add .utf8 to your $locale string
第二 - 如果未安装该语言,请使用 locale -a 检查您的系统是否支持该语言,例如 de_DE:sudo apt-get install language-pack-de-base

$locale = "de_DE.utf8";
if (isset($_GET["locale"])) $locale = $_GET["locale"];

$domain = 'messages';
$directory = dirname(__FILE__);//your path to locale folder may differ

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

Maybe much too late, but I had the same problem:

1st -You need to add .utf8 to your $locale string
2nd - 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

$locale = "de_DE.utf8";
if (isset($_GET["locale"])) $locale = $_GET["locale"];

$domain = 'messages';
$directory = dirname(__FILE__);//your path to locale folder may differ

setlocale( LC_MESSAGES, $locale);
bindtextdomain($domain, $directory);
textdomain($domain);
bind_textdomain_codeset($domain, 'UTF-8');
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文