0

我正在使用 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');
    }
}

我想知道我哪里出错了?

有人可以帮忙吗?

谢谢

4

1 回答 1

1

I18n::translate()在 case set 中使用Configure.language会话值而不是配置值,但转换行为不会,它仅依赖于配置值

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

也可以看看

于 2016-01-05T09:08:17.053 回答