PHP& GetText在我的服务器上无法正常工作

时间:2011-03-18 11:29:47

标签: php gettext

我正在尝试设置gettext来翻译我的网站,但我继续在我的服务器上出现奇怪的行为。

在我的ubuntu机器上本地工作正常,但在我的centos 5.5专用服务器上,只翻译了我的部分页面,当我刷新页面时,它实际上改变了翻译的部分。

我知道这听起来很疯狂。

apache日志中没有任何内容。

帮助,我迷路了:'(

2 个答案:

答案 0 :(得分:2)

PHP中的Gettext存在问题。 http://bugs.php.net/search.php?cmd=display&search_for=gettext&x=0&y=0 - 你可能碰到了一个。

我无法提供修复或良好的调试方法,但是:

  • 制作测试脚本,遍历所有已知字符串。用不同的字符集测试。
  • 尝试升级 - 如果是这种情况,请从5.2升级到php 5.3。
  • 或者卸载php.ini中的gettext模块。而是通过dl()动态加载它。
    • 性能不佳,但可能会减少与运行时/内存相关的错误。 (这听起来像。)
  • 不要使用gettext.so,但脚本实现php-gettext或upgradephp gettext.php(停止间隙测量)

答案 1 :(得分:0)

1a)如果您的网络服务器上存在区域设置,请使用“locale -a”进行检查 1b)如果您可以设置语言环境

,请在没有shell的情况下尝试使用此代码
echo setlocale(LC_ALL, 0);     // read the current locale
setlocale(LC_ALL, "fa");       // try to write your locale
echo setlocale(LC_ALL, 0);     // check if your was accepted

2a)如果缺少语言环境,请添加,例如使用“apt-get install locales” 2b)如果您没有root权限,请使用https://launchpad.net/php-gettext作为替代。

<?php

$locale = "fa";

// Define location and domain of translations
$directory = realpath('./') .'/translations/LOCALES';
$domain    = 'php-addressbook';
$default_locale = $locale;
$supported_locales = array($locale);


// Prepare "php-gettext"
require_once('gettext/gettext.inc');


// Prepare "native gettext" setup
T_setlocale(LC_ALL, $locale);
T_bindtextdomain($domain, $directory);
T_textdomain($domain);
T_bind_textdomain_codeset($domain, 'UTF-8');

echo T_gettext('ADDRESS');

if (!locale_emulation()) {
    print "<p>locale '$locale' is supported by your system, using native gettext implementation.</p>\n";
}
else {
    print "<p>locale '$locale' is _not_ supported on your system, using the default locale '". $default_locale ."'.</p>\n";
}

?>