Cakephp的翻译行为默认行为无效

时间:2011-09-13 11:14:19

标签: cakephp internationalization translation behavior

有人可以建议我为什么当一个字段没有翻译时,它会返回为空,而不是默认翻译?

我将感谢所有建议......

无法告诉我想要查看的代码的哪一部分,因为它直接来自www.book.cake.org。所以我粘贴了一些代码:

模型定义:

<?php
class Article extends AppModel
{
    var $useTable = 'nc_articles';
    var $name = 'Article';
    var $actsAs = array(
        'Translate' => array(
        'title', 'content', 'meta_key_words','meta_description'
        )
    );
    // Use a different model
    var $translateModel = 'ArticlesI18n';
    // Use a different table for translateModel
    var $translateTable = 'nc_articles_i18ns';
    var $belongsTo = array(
        'Author' => array('className' => 'User',
            'foreignKey' => 'author_id',
            'conditions' => '',
            'fields' => array(),
            'order' => '',
            'counterCache' => ''),       
        'Modifier' => array('className' => 'User',
            'foreignKey' => 'modifier_id',
            'conditions' => '',
            'fields' => array(),
            'order' => '',
            'counterCache' => ''),   
        'Category' => array('className' => 'ArticlesCategory',
            'foreignKey' => 'category_id',
            'conditions' => '',
            'fields' => array(),
            'order' => '',
            'counterCache' => ''),   
        'Layout' => array('className' => 'Layout',
            'foreignKey' => 'layout_id',
            'conditions' => '',
            'fields' => array(),
            'order' => '',
            'counterCache' => ''),        
        );
    var $hasMany = array(
        'Comments' => array(
            'className' => 'ArticlesComment',
            'foreignKey' => 'article_id',
            'conditions' => array(),
            'order' => '',
            'limit' => '',
            //'dependent'=> true When dependent is set to true, recursive model deletion is possible. In this example, Comment records will be deleted when their associated User record has been deleted. 
            )
        ); 


}
?>

然后我改变语言的功能:

function setLanguage($languageCode='pol')
{
    $this->Session->write('Config.language', $languageCode);
    $this->redirect($this->referer());
}

您想再看一些吗?

1 个答案:

答案 0 :(得分:3)

让我回答我自己的问题。我不得不写更多的东西。首先,我必须在core.php中声明我的Config.language然后为每个被翻译的模型我必须声明一个局部变量,这是一个语言代码数组

$this->Article->array('en','pol');

这就是我解决问题的方法。但是现在对翻译的查询很长,我面临着一个优化问题。