Cakephp 2.6 国际化

Cakephp 2.6 internationalization

我正在使用 i18n 和翻译行为为我的网站进行翻译。

一旦用户点击更改语言按钮。所有文字和记录都将以中文显示。

但是,

当用户点击其他页面时,只有通过 i18n 翻译的文本仍然显示为中文。数据库记录显示为英文原件。

这是 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');
    }
}

我在想我哪里做错了?

有人可以帮忙吗?

谢谢

I18n::translate() 仅使用 Configure.language session value over the configuration value in case set, but the translate behavior will not, it relies on the configuration value

您似乎没有设置 Configure.language 配置值 (Configure::write('Config.language', $language)),因此翻译行为将使用您的配置中定义的默认值(如果存在),因此没有翻译内容即将被阅读。

另见