我在 PHP 中使用 gettext 时遇到问题;我有两台服务器,一台是本地服务器(我在其中开发),在 Windows 中(使用 vs.php)并工作查找,另一台在 Amazon EC2 中(更新了 Ubuntu 12.04),这是生产服务器,在这台服务器中,相同的代码不发现了。
这是我的代码:
我用这个来初始化 gettext 。
function initialize_i18n($locale) {
$locales_root = "./librerias/noAuto/locale";
putenv('LANG='.$locale);
putenv("LC_ALL=" . $locale);
setlocale(LC_ALL,$locale);
$domains = glob($locales_root.'/'.$locale.'/LC_MESSAGES/messages*.mo');
if (count ($domains) > 0)
{
$current = basename($domains[0],'.mo');
$timestamp = preg_replace('{messages-}i','',$current);
bindtextdomain($current,$locales_root);
bind_textdomain_codeset( $current, "UTF-8" );
textdomain($current);
if ($locale == "en_US")
{
if( _("Modificar") === "Modify" ) {
$system->setDebug( "Translated correctly");
} else {
$system->setDebug( "Gettext don't working");
}
}
}
}
initialize_i18n("en_US");
Run Code Online (Sandbox Code Playgroud)
我的项目中的所有文件均以 UTF-8(西班牙语)编码,并且 .mo 和 .po …