【问题标题】:php-gettext don't work in production server. (Ubuntu)php-gettext 在生产服务器中不起作用。 (Ubuntu)
【发布时间】:2012-09-04 10:21:56
【问题描述】:

我在 PHP 中遇到了 gettext 问题;我有两台服务器,一台是本地服务器(我在其中开发)在 Windows 中(使用 vs.php)和工作查找,另一台在 Amazon EC2 中(Ubuntu 12.04 更新),这是生产服务器,在此服务器中相同的代码不要'没有找到。

这是我的代码:

我用这个初始化gettext。

function initialize_i18n($locale) {
    $locales_root = "./librerias/noAuto/locale";
    putenv('LANG='.$locale);
    putenv("LC_ALL=" . $locale);
    setlocale(LC_ALL,$locale);
    $domains = glob($locales_root.'/'.$locale.'/LC_MESSAGES/messages*.mo');
    if (count ($domains) > 0)
    {
        $current = basename($domains[0],'.mo');
        $timestamp = preg_replace('{messages-}i','',$current);
        bindtextdomain($current,$locales_root);
        bind_textdomain_codeset( $current, "UTF-8" );
        textdomain($current);
        if ($locale == "en_US")
        {
            if( _("Modificar") === "Modify" ) {
                $system->setDebug( "Translated correctly");
            } else {
                $system->setDebug( "Gettext don't working");
            }
        }
    }
}
initialize_i18n("en_US");

我项目中的所有文件都以 UTF-8(西班牙语)编码,并且 .mo 和 .po 已使用 poedit 生成。

我尝试重新加载 apache 服务但没有成功。

有什么想法吗?

【问题讨论】:

    标签: php internationalization gettext ubuntu-server php-gettext


    【解决方案1】:

    新的一天新的想法!我有办法!

    我也有同样的问题,你需要检查这个步骤。

    1 - 您的 Linux 安装了这种语言?

    你可以用这个检查:

     locale -a
    

    如果没有列出您的语言,请安装它,例如,您可以安装 englsh 本地化:

     # aptitude install language-pack-en
    

    完成后重启apache。

    2 - 您的语言代码在 PHP 中是否正确?

    如果您使用 locale -a 列出语言代码列表,您将看到可以使用的语言代码,例如,我的系统列出的英语: [...] en_NG.utf8 en_NZ.utf8 en_PH.utf8 en_SG.utf8 en_US.utf8 [...] 我的一个错误是,我使用“en_US”而不是“en_US.utf8”。

    3 - 文件夹的名称与语言代码相同。 (我的第二个错误)

    PD>对不起我的英语不好

    【讨论】:

    • 救命稻草!我会花几个小时来思考这个方向:) 谢谢!
    【解决方案2】:

    如果在不同的环境下不能正常工作,最好检查关键功能是否处理成功。

    我建议你先检查 bindtextdomain() 和 bind_textdomain_codeset() 的返回值。如果它们返回空白,则意味着 PHP 找不到消息资源文件(仅在 Ubuntu 上),那么您可以检查运行 Web 服务器和 PHP 的 Unix 用户的文件夹和文件的权限。

    【讨论】:

    • 感谢您的宝贵时间,我尝试了您的建议,这是 de 输出:bindtextdomain($current,$locales_root) -> /home/gudymail/librerias/noAuto/locale ---- bind_textdomain_codeset( $ current, "UTF-8" ) -> UTF-8 ----- textdomain($current) -> messages ---- 这是预期的吗?
    猜你喜欢
    • 2015-09-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-01-27
    • 1970-01-01
    相关资源
    最近更新 更多