【问题标题】:Cakephp 3 does not work for the default languageCakephp 3 不适用于默认语言
【发布时间】:2016-06-19 05:59:57
【问题描述】:

对不起我的英语,但我希望你能理解我。 简化后的代码如下所示:

//在bootstrap.php中

ini_set('intl.default_locale', 'deu');

// MainMenusTable.php

公共函数初始化(数组 $config) { 父::初始化($config); ...

    $this->addBehavior('Translate', ['fields' => ['title']]);  

... }

//在控制器中 - 这有效!

public function add()
{

    I18n::locale('eng');
    $mainMenu = $this->MainMenus->newEntity();
    if ($this->request->is('post')) {     
        $mainMenu = $this->MainMenus->patchEntity($mainMenu, $this->request->data);
        $this->MainMenus->save($mainMenu)
    }
    $this->set(compact('mainMenu'));
}

// 在控制器中但这不起作用:

public function add()
{

    I18n::locale('deu');
    $mainMenu = $this->MainMenus->newEntity();
    if ($this->request->is('post')) {     
        $mainMenu = $this->MainMenus->patchEntity($mainMenu, $this->request->data);
        $this->MainMenus->save($mainMenu)
    }
    $this->set(compact('mainMenu'));
}

我在阅读记录时也遇到了同样的问题

//在控制器中 - 这有效!

    I18n::locale('eng');      
    $query = $this->MainMenus->find('all')->order(['MainMenus.id' => 'ASC'])->all();

// 在控制器中但这不起作用:

    I18n::locale('deu');      
    $query = $this->MainMenus->find('all')->order(['MainMenus.id' => 'ASC'])->all();

对于“deu”,我手动输入了记录。 你知道问题是什么吗? 谢谢!

【问题讨论】:

    标签: internationalization behavior translate


    【解决方案1】:

    这是来自https://github.com/cakephp/cakephp/issues/8416的问题解决方案:

    该行为假定您以默认语言存储记录。如果当前语言环境与默认语言相同,那么它只会返回数据库中的记录,而不是从翻译表中获取。

    默认语言的标题不会保存在 i18n 表中,只有其他语言才会这样做。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-04-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多