【发布时间】:2016-01-05 04:55:05
【问题描述】:
我正在使用 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');
}
}
我想知道我哪里出错了?
有人可以帮忙吗?
谢谢
【问题讨论】:
-
请始终指定您使用的确切 CakePHP 版本!另请说明您如何/在何处设置实际的
Config.languageconfiguration 值(不是会话值)!
标签: cakephp internationalization cakephp-2.6 cakephp-2.x