我正在编写一个 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/