如何在php中使用gettext?
我在我的webdir的lang文件夹中有一个文件如何在php中使用gettext?,php,gettext,Php,Gettext,我在我的webdir的lang文件夹中有一个文件dk.po和dk.mo 如何使用此文件?我都试过了,但没能成功 // Lang putenv('LC_ALL=dk'); setlocale(LC_ALL, 'dk'); // Specify location of translation tables bindtextdomain("dk", ROOT .'lang'); // Choose domain textdomain("dk"); 这对我有用 我的文件名为messages.mo
dk.po
和dk.mo
如何使用此文件?我都试过了,但没能成功
// Lang
putenv('LC_ALL=dk');
setlocale(LC_ALL, 'dk');
// Specify location of translation tables
bindtextdomain("dk", ROOT .'lang');
// Choose domain
textdomain("dk");
这对我有用
我的文件名为messages.mo
static function initialize_i18n() {
$locale=App::$locale;
$locales_root = App::$root."locale";
putenv('LANG='.$locale);
putenv('LANGUAGE='.$locale);
putenv('LC_ALL='.$locale);
putenv('LC_MESSAGES='.$locale);
setlocale(LC_ALL, $locale.".utf-8");
$domains = glob($locales_root.'/'.$locale.'/LC_MESSAGES/messages-*.mo');
$current = basename($domains[0],'.mo');
$timestamp = preg_replace('{messages-}i','',$current);
bindtextdomain("messages",$locales_root);
textdomain("messages");
}
我非常推荐使用
Zend_Translate
,因为在各种类型的系统上,您可能会遇到许多与locale
不一致的情况
文档:我已经在处理这个问题了:
setlocale(LC_ALL, 'ar_LY.utf8');
bindtextdomain("trans", $_SERVER["DOCUMENT_ROOT"].'/trans/locale');
textdomain("trans");
语言文件路径:
/var/www/trans/locale/ar_LY/LC_MESSAGES/trans.mo
我认为(不确定)你必须使用相同的路径 如果我有一个大项目,我能把它翻译成这个吗?或者这会很难吗?只要抓取整个Zend库并只包含Zend Translate类,您就应该很好了。您不需要使用
gettext
php函数,因为Zend提供了自己的整个gettext实现。不过有一件事,您的主机必须使用PHP5,否则Zend将无法工作。hmmm,我不太明白:/i已将文件放入此文件夹/var/www/domain.com/lang/dk/dk.mo您能从这些信息中提取一个示例吗?很抱歉我的变量。。将$locale替换为“lang/dk”,将App:$root替换为“/var/www/domain.com/”我想知道在之前调用setlocale时是否有必要调用putenv(“…”)?@Leto据我所知,putenv调用是为了Windows兼容性。