1
votes

I have four tables:

gallery_categories table: id (int); title (varchar);

gallery_pictures table: id (int); title (varchar);

gallery_categories_gallery_pictures table to joint above tables: gallery_category_id (int); gallery_picture_id (int);

and the i18n table: id (int) locale (varchar) model (varchar) foreign_key (int) field (varchar) content (text)

I tried:

$this->GalleryCategory->bindModel(array(
            'hasOne' => array(
                'GalleryCategoriesGalleryPicture',
                'GalleryPicture' => array(
                    'className' => 'GalleryPicture',
                    'foreignKey' => false,
                    'conditions' => array('GalleryPicture.id = GalleryCategoriesGalleryPicture.gallery_picture_id')
            ))));
            $galleryCategories = $this->GalleryCategory->find('all', array(
                'fields' => array('GalleryCategory.*','GalleryPicture.*')
            ));

But all time it returns with the right Category table fields and wrong Pictures table fields... The Category fields contain the right translated words. The Pictrures fields contain the wrong translated words.

The Models:

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

    public $actsAs = array('Translate' => array(
                                                'title'             => 'titleTranslation'
                                                )
                            );
}



class GalleryPicture extends AppModel
{
    public $tablePrefix = 'ef_';
    var $name = 'GalleryPicture';

    public $actsAs = array('Translate' => array(
                                                'title'             => 'titleTranslation'
                                                )
                            );
}

How could I get the right translated words from both table?

ps: The translation with "i18n Database Tables" works right with only one table (exp: only GalleryCategory or only GalleryPicture).

1

1 Answers

1
votes

Translation doesn't work with associated models, see the last couple of lines here:

Note that only fields of the model you are directly doing find on will be translated. Models attached via associations won’t be translated because triggering callbacks on associated models is currently not supported.

Update It might be tricky, as you have a HABTM relationship - previously I have worked around this by adding a second data retrieval to the afterFind callback of a model, but this was with a simpler association. Hope this helps.