我正在尝试使用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下创建了转换文件
我在Ubuntu11.04 (natty),PHP5.3.5-1ubuntu7.3,apache2下试用
有什么建议吗?
发布于 2011-12-04 17:22:07
尝试:
<?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');
?>
发布于 2013-05-06 09:13:10
也许太晚了,但我也有同样的问题:
1 -You需要将.utf8
添加到您的$locale
字符串中2-如果未安装语言,请使用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');
https://stackoverflow.com/questions/8377072
复制相似问题