Cake php默认bahaviour为翻译行为不工作 [英] Cake php default bahaviour for Translate behaviour not working

查看:207
本文介绍了Cake php默认bahaviour为翻译行为不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都可以建议我为什么没有翻译的字段,它返回为空,而不是默认翻译?

Can anyone suggest me why when there are no translation for a field it is returned empty, and not with the default translation?

我会感谢所有建议。 。

I will appreciate all suggestions...

不能告诉我的代码的哪部分,你想看到,因为它是直接从www.book.cake.org。所以我粘贴了一些代码:

Can`t tell what part of my code you want to see, because it is all straight forward from www.book.cake.org. So i pasting some code:

模型定义:

<?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. 
            )
        ); 


}
?>

然后我正在改变的功能语言:

And then the function where I am changing Language:

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

您想再看一些吗?

推荐答案

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

Let me answer my own question. There were few more things I had to write more. First of all I had to declare my Config.language in core.php then for Every model which is translated I had to declare a local variable which is an array of language codes

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

这是我如何管理这个问题。但现在查询翻译很长,我面临一个优化问题。

And that's how I managed the problem. But now queries for translation are very long and I am facing an optimization problem.

这篇关于Cake php默认bahaviour为翻译行为不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆