我正在编写一个PHP应用程序并使用gettext模块翻译成不同的语言。
代码在我的本地计算机上运行(运行WAMP的Windows),但我无法在服务器上运行(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)计算机上运行,但在服务器上显示原始字符串(未翻译)...
我还需要配置其他内容吗?
答案 0 :(得分:2)
尝试在Linux计算机上运行locale -a以检查语言环境是否已正确安装