我怎样才能从i18n表中得到一个结果? (CakePHP的)

时间:2013-04-27 08:36:39

标签: cakephp internationalization multilingual

我查询表格中的所有行,并获得所有语言的所有行...

例如: GalleryCategoriesController.php

<?php
class GalleryCategoriesController extends AppController
    {
    function index()
        {
        $galleryCategories = $this->GalleryCategory->find('all');
        print_r($galleryCategories);
        $this->set('galleryCategories', $galleryCategories);
        }
    }
?>

GalleryCategory.php(模特)

<?php
class GalleryCategory extends AppModel
    {
    public $tablePrefix = 'ef_';
    var $name = 'GalleryCategory';

    public $actsAs = array('Translate' => array(
            'title' => 'titleTranslation',
            'title_sub' => 'titleSubTranslation',
            'description' => 'descriptionTranslation'
            )
        );
    }
?>

结果:

Array
    (
    [0] => Array
        (
        [GalleryCategory] => Array 
            (
            [id] => 1
            [gallery_category_id] => 0
            [title] => Test title
            [title_sub] => Test subtitle
            [description] => Test description
            [status] => 2
            [locale] => hun
            )
         [titleTranslation] => Array
            (
            [0] => Array
                (
                [id] => 65
                [locale] => hun
                [model] => GalleryCategory
                [foreign_key] => 1
                [field] => title
                [content] => Test title hungarian
                )
            [1] => Array
                (
                [id] => 80 
                [locale] => eng 
                [model] => GalleryCategory 
                [foreign_key] => 1 
                [field] => title 
                [content] => Test title english
                ) 
            )
         [titleSubTranslation] => Array 
            ( 
            [0] => Array 
                ( 
                [id] => 66 
                [locale] => hun 
                [model] => GalleryCategory 
                [foreign_key] => 1 
                [field] => title_sub 
                [content] => Test subtitle hungarian
                ) 
            [1] => Array 
                ( 
                [id] => 81 
                [locale] => eng 
                [model] => GalleryCategory 
                [foreign_key] => 1 
                [field] => title_sub 
                [content] => Test subtitle english
                ) 
            ) 
         [descriptionTranslation] => Array 
            ( 
            [0] => Array 
                ( 
                [id] => 67 
                [locale] => hun 
                [model] => GalleryCategory 
                [foreign_key] => 1 
                [field] => description 
                [content] => Test description hungarian
                )
            [1] => Array 
                ( 
                [id] => 82 
                [locale] => eng 
                [model] => GalleryCategory 
                [foreign_key] => 1 
                [field] => description 
                [content] => Test description english
                ) 
            ) 
         ) 
     )

我怎么才能获得匈牙利语翻译?因为如果我在网站上有六种语言,并且我查询任何内容,我会用六种语言来获取它...这太糟糕了......

1 个答案:

答案 0 :(得分:1)

您的模型定义必须根据the manual进行更改: 尝试类似:

<?php
class GalleryCategory extends AppModel
    {
    public $tablePrefix = 'ef_';
    var $name = 'GalleryCategory';

    public $actsAs = array('Translate' => array(
            'title', 'title_sub', 'description'
            )
        );
    }
?>

当然,您还需要选择以下语言环境:

$this->GalleryCategory->locale = <hun|eng>
控制器操作中的

相关问题