php - 无法使语言环境在 Linux 上工作

标签 php linux unix locale

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

代码在我的本地计算机(Windows 运行 WAMP)上运行正常,但我无法在服务器上运行(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”来安装语言组件。

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

我还需要配置什么吗?

最佳答案

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

关于php - 无法使语言环境在 Linux 上工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5910252/

相关文章:

linux scp/sftp命令

shell - 有没有办法在关机后自动启动基于 unix 的系统?

java - 将数据从 PHP 传输到 Java

javascript - Nette PHP 框架和带有 token 认证的 RESTful API

linux - Linux Mint 中的“RUN”不起作用

python - 如何正确使用 python 访问系统命令并使我的脚本工作?

linux - 使用 AWK 比较两个不同的文件并将值从一个文件复制到另一个文件

c - 以什么方式,fork() 系统调用生成子进程?

php - Android 上的 HTTP POST

php - 如何使用自适应 Paypal API 退还部分金额