Cake php 翻译行为的默认行为不起作用

发布于 2024-12-04 19:53:29 字数 2331 浏览 1 评论 0原文

谁能告诉我为什么当字段没有翻译时它会返回空,而不是默认翻译?

我将不胜感激所有的建议...

无法说出您想查看我的代码的哪一部分,因为它都是直接来自 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());
}

你想看到更多东西吗?

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...

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:

Model definition:

<?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());
}

Would you like to see something more?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

叶落知秋 2024-12-11 19:53:29

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

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

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

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文