2011-02-12 29 views
1

我添加了一個用於gettext轉換的庫。添加了相應的po和mo文件。codeigniter中的gettext問題

而且翻譯工作正常。

現在,當我更新我的po文件,改變一些翻譯..之後,當我重新加載頁面,我得到舊的翻譯,而不是新的。

這裏是圖書館代碼:

/** 
* This method overides the original load method. Its duty is loading the domain files by config or by default internal settings. 
* 
*/ 
function load_gettext($userlang = false) { 

    /* I want the super object */ 
    if ($userlang) 
     $this->gettext_language = $userlang; 
    else 
     $this->gettext_language = 'it_IT'; 
    log_message('debug', 'Gettext Class gettext_language was set by parameter:' . $this->gettext_language); 

    putenv("LANG=$this->gettext_language"); 
    setlocale(LC_ALL, $this->gettext_language); 

    /* Let's set the path of .po files */ 
    $this->gettext_path = APPPATH . 'language/locale'; 
    log_message('debug', 'Gettext Class path chosen is: ' . $this->gettext_path); 

    bindtextdomain($this->gettext_domain, $this->gettext_path); 
    textdomain($this->gettext_domain); 
    log_message('debug', 'Gettext Class the domain chosen is: ' . $this->gettext_domain); 
    return true; 
} 

/** 
* Plural forms added by Tchinkatchuk 
* http://www.codeigniter.com/forums/viewthread/2168/ 
*/ 

/** 
* The translator method 
* 
* @param string $original the original string to translate 
* @param array $aParams the plural parameters 
* @return the string translated 
*/ 
function _trans($original, $aParams = false) { 
    if (isset($aParams['plural']) && isset($aParams['count'])) { 
     $sTranslate = ngettext($original, $aParams['plural'], $aParams['count']); 
     $sTranslate = $this->replaceDynamically($sTranslate, $aParams); 
    } else { 
     $sTranslate = gettext($original); 
     if (is_array($aParams) && count($aParams)) 
      $sTranslate = $this->replaceDynamically($sTranslate, $aParams); 
    } 
    return $sTranslate; 
} 

這是在控制器的使用:

$this->pos_language->load_gettext('fr_FR'); 
echo $this->pos_language->_trans('Hello world, good morning'); 
+0

你有沒有重新啓動編輯Apache(假設這是你使用的Web服務器)? – salathe 2011-02-12 11:57:52

回答

1

我認爲你需要編譯你的.po文件的.mo文件。 Gettext使用.mo文件,.po只是一種人類可讀的形式。

如果你還沒有完成編譯步驟,您的應用程序仍然在讀你的舊的.mo文件,與未翻譯的字符串...

此頁面有關於gettext的翻譯一些更多的信息:http://wiki.creativecommons.org/Translating_PO_Files

+0

謝謝..那是我認爲的問題,現在它正在像一個魅力:)乾杯...... – viMaL 2011-02-14 03:56:03