can't make locale work on Linux

耗尽温柔 提交于 2021-02-10 18:51:34

问题


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

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");
}

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

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?


回答1:


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



来源:https://stackoverflow.com/questions/5910252/cant-make-locale-work-on-linux

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!