簡體   English   中英

如何在php中使用gettext?

[英]how to use gettext in php?

我的dk.mo文件夾lang中有一個文件dk.podk.mo

如何使用此文件? 我已經嘗試了所有方法,但是無法正常工作。

// Lang
putenv('LC_ALL=dk');
setlocale(LC_ALL, 'dk');

// Specify location of translation tables
bindtextdomain("dk", ROOT .'lang');

// Choose domain
textdomain("dk");

我已經在用這個了:

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

而且我認為(不確定)您必須使用相同的路徑!

這對我有用,我的文件名為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建議為此使用Zend_Translate ,因為您可能會遇到與各種類型的系統上的locales不一致的情況。

文件: http : //framework.zend.com/manual/en/zend.translate.using.html

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM