2010-07-12 148 views
2

我使用CakePHP 1.3.2與集成的翻譯行爲。CakePHP TranslateBehavior讓我瘋狂

翻譯我保存我的幾個模型在每個表中。例如:

class Page extends AppModel { 
    var $name = 'Page'; 
    var $actsAs = array(
     'Translate' => array('title', 'subtitle', 'menu') 
    ); 
    var $translateModel = 'PageI18n'; 
... 
} 

現在插入一些數據行後。 Cake不再檢索索引操作中的i18n數據。在SQL轉儲看起來是這樣的:

... WHERE I18n__title.locale = 'de_de' ... 

但在表中「page_i18ns」語言環境領域充滿了「

爲什麼蛋糕混合區域設置屬性?我應該在哪裏設置locale屬性? Model類中的某處?

在我的AppController我在beforeFilter()功能設置語言與Configure::write('Config.language', $lang); .... '工程', '申', '智'

+0

我知道蛋糕和語言環境,但沒有使用的翻譯行爲。我只想提到,區域設置標識符看起來像en_en,de_de等,不像eng和deu。 – sibidiba 2010-07-12 18:20:37

回答

1

我在ArticlesController下面的代碼:

function beforeFilter() { 
    parent::beforeFilter(); 
    $this->Article->locale = $this->Session->read('Config.language'); 
} 

看看是否有幫助。

+0

謝謝奧斯卡獎。在我的情況下: $ this-> Article-> locale = Configure :: read('lang'); – hasentopf 2010-07-16 07:03:29

0

確實令人討厭CakePHP使用語言環境而不是i18n表中的語言。
他們可能會修復這個bug,但機會很渺茫,因爲修復這個bug會打破所有現有的i18n應用程序。

所以我寫了一個翻譯成語言代碼語言環境一個小幫手功能:

/** 
* Retrieve the "locale" from the language code (for i18n table) 
* Examples: en -> eng, en-us -> en_us, de -> deu, nl -> dut 
* 
* @param string $language 
* @return string 
*/ 
function convertLanguageToLocale($language) { 
    $i18n =& I18n::getInstance(); 
    $i18n->l10n->get($language); 
    return $i18n->l10n->locale; 
}