无法在Linux上使语言环境正常工作 [英] can't make locale work on Linux

查看:76
本文介绍了无法在Linux上使语言环境正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个PHP应用程序,并使用gettext模块将其翻译成不同的语言.

I am writing an PHP application and using the gettext module to translate to different languages.

代码在我的本地计算机(运行WAMP的Windows)上按预期工作,但是我无法使其在服务器(Unix + apache2)上工作

The code is working as I expect on my local computer (Windows running WAMP), but i can't make it work on the server (Unix + apache2)

{
        $locale_folder = dirname(dirname(dirname(__FILE__))).'/locale/';
        $locale = 'he_IL';


        $domain = 'myapp';
        $autoreload = true;

        // activate the locale setting
        setlocale(LC_ALL, $locale);
        setlocale(LC_TIME, $locale);

        putenv("LANG=$locale");
        putenv("LANGUAGE=$locale");
        putenv("LC_ALL=$locale");
        putenv("LC_MESSAGES=$locale");

        if ($autoreload) {
            // path to the .MO file that we should monitor
            $filename = "$locale_folder/$locale/LC_MESSAGES/$domain.mo";
            $mtime = filemtime($filename); // check its modification time
            // our new unique .MO file
            $filename_new = "$locale_folder/$locale/LC_MESSAGES/{$domain}_{$mtime}.mo"; 

            if (!file_exists($filename_new)) {  // check if we have created it before
                  // if not, create it now, by copying the original
                  copy($filename,$filename_new);
            }

            // compute the new domain name
            $domain_new = "{$domain}_{$mtime}";
        } else {
                $domain_new = $domain;
        }

        // bind it
        bindtextdomain($domain_new,$locale_folder);
        // then activate it
        textdomain($domain_new);

        bind_textdomain_codeset($domain_new, "UTF-8");
}

我以前已经运行过"sudo locale-get he_IL"和"sudo locale-get he_IL.UTF-8"来安装语言组件.

I had run "sudo locale-get he_IL" and "sudo locale-get he_IL.UTF-8" previously to install the language component.

翻译工作在本地(Windows)计算机上,但在服务器上显示了原始字符串(未翻译)...

The translation is working on the local (Windows) computer but displays the original strings (not translated) on the server...

我还需要配置其他内容吗?

Do I have to configure anything else?

推荐答案

尝试在Linux机器上运行语言环境-a,检查语言环境是否正确安装

Try to run locale -a on your Linux machine to check if the locale is installed correctly

这篇关于无法在Linux上使语言环境正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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