【问题标题】:Cakephp 2.6 internationalizationCakephp 2.6 国际化
【发布时间】: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.language configuration 值(不是会话值)!

标签: cakephp internationalization cakephp-2.6 cakephp-2.x


【解决方案1】:

I18n::translate() 使用Configure.language session value over the configuration value 设置大小写,但翻译行为不会,它仅relies on the configuration value

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

另见

【讨论】:

    猜你喜欢
    • 2015-08-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-11-25
    • 1970-01-01
    • 1970-01-01
    • 2011-02-23
    相关资源
    最近更新 更多