2016-01-05 155 views
0

我在爲我的網站使用i18n和翻譯行爲做翻譯。Cakephp 2.6國際化

一旦用戶點擊更改語言按鈕。所有的文本和記錄將以中文顯示。

但是,

當其他網頁的用戶點擊,只有文本,通過國際化翻譯在中國仍然顯示。數據庫記錄顯示爲英文原文。

這是在AppController中

function beforeFilter() { 
    $this->_setLanguage(); 
} 

private function _setLanguage() { 

//if the cookie was previously set, and Config.language has not been set 
//write the Config.language with the value from the Cookie 
    if ($this->Cookie->read('lang') && !$this->Session->check('Config.language')) { 
     $this->Session->write('Config.language', $this->Cookie->read('lang')); 
    } 

//if the session was previously set, and cookie language has not been set 
//write the cookie language with the value from the session 

    else if (!$this->Cookie->read('lang') && $this->Session->check('Config.language')) { 
     $this->Cookie->write('lang', $this->Session->read('Config.language')); 
    } 
    //if the user clicked the language URL 

    if (isset($this->params['language'])) { 
     //then update the value in Session and the one in Cookie 
     $this->Session->write('Config.language', $this->params['language']); 
     $this->Cookie->write('lang', $this->params['language'], false, '20 days'); 
    } 
} 

我不知道爲什麼我找到了問題所在的代碼?

任何人都可以幫忙嗎?

感謝

+1

請始終指定要使用的確切CakePHP的版本!還請顯示如何/在哪裏設置實際的'Config.language' [**配置**](http://book.cakephp.org/2.0/en/development/configuration.html#configure-class)值(不是會話值)! – ndm

回答

1

I18n::translate()使用的情況下,集中Configure.language session value over the configuration value,但翻譯行爲不會,它relies on the configuration value只。

您似乎沒有設置Configure.language配置值(Configure::write('Config.language', $language)),因此翻譯行爲將使用您的配置中定義的默認值(如果存在),因此不會讀取翻譯的內容。

又見