# Translate contain Cakephp ~3.1

**URL:** <https://discourse.cakephp.org/t/translate-contain-cakephp-3-1/1141>\
**Category:** Need Help\
**Tags:** translation, i18n\
**Created:** [September 11, 2016, 5:12am UTC](https://discourse.cakephp.org/t/translate-contain-cakephp-3-1/1141 "2016-09-11T05:12:50Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bed0skil](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/bed0skil/32/388_2.png) [@Bed0skil](https://discourse.cakephp.org/u/Bed0skil)\
**Post date:** [September 11, 2016, 5:12am UTC](https://discourse.cakephp.org/t/translate-contain-cakephp-3-1/1141/1 "2016-09-11T05:12:50Z")

</div>

Hello everyone, i would like translate the data **associated** Metas of my Post

`PostsTable`

```
public function initialize(array $config)
    {
        parent::initialize($config);

        [...]

        $this->hasMany('Metas', [
            'foreignKey' => 'post_id'
        ]);

        $this->addBehavior('Translate', ['fields' => ['title', 'body', 'slug'], 'allowEmptyTranslations' => true]);
    }

```

`MetasTable`

```
public function initialize(array $config)
    {
        parent::initialize($config);

        [...]

        $this->belongsTo('Posts', [
            'foreignKey' => 'post_id'
        ]);

        $this->addBehavior('Translate', ['fields' => ['meta_value'], 'allowEmptyTranslations' => true]);
    }

```

`debug($this->request->data);`

```
'fr' => [
    'title' => 'Titre en Français',
    'slug' => '',
    'body' => '<p>...</p>',
    'online' => '0',
    'category_id' => '1',
    'type_id' => '2',
    'metas' => [
        (int) 0 => [
            'meta_key' => 'picture',
            'type_id' => '2',
            'meta_value' => 'url de l'image en FR'
        ],
        (int) 1 => [
            'meta_key' => 'laureat_actuel',
            'type_id' => '2',
            'meta_value' => 'url de la photo en FR'
        ],
        (int) 2 => [
            'meta_key' => 'date',
            'type_id' => '2',
            'meta_value' => 'date en FR'
        ],
        (int) 3 => [
            'meta_key' => 'nom',
            'type_id' => '2',
            'meta_value' => 'Nom en FR'
        ],
        (int) 4 => [
            'meta_key' => 'bio',
            'type_id' => '2',
            'meta_value' => 'Bio en FR'
        ]
    ]
],
'gb' => [
    'title' => 'Titre en GB',
    'slug' => '',
    'body' => '<p>...</p>',
    'metas' => [
        (int) 0 => [
            'meta_key' => 'picture',
            'type_id' => '2',
            'meta_value' => 'url en GB'
        ],
        (int) 1 => [
            'meta_key' => 'laureat_actuel',
            'type_id' => '2',
            'meta_value' => 'photo en GB'
        ],
        (int) 2 => [
            'meta_key' => 'date',
            'type_id' => '2',
            'meta_value' => 'date GB'
        ],
        (int) 3 => [
            'meta_key' => 'nom',
            'type_id' => '2',
            'meta_value' => 'nom GB'
        ],
        (int) 4 => [
            'meta_key' => 'bio',
            'type_id' => '2',
            'meta_value' => 'bio GB'
        ]
    ]
]

```

After have post this data, the translation is good in my PostsTable, with the associated Metas, But the Metas are not translated

Here’s how I save my translations:

```
$post = $this->Posts->newEntity($this->request->data, ['translations' => true]);
$post = $this->Posts->patchEntity(
    $post, 
    $this->request->data,
    [
        'associated' => ['Metas']
    ]
);

$translations = $this->request->data;

foreach ($translations as $lang => $data) {
    $post->translation($lang)->set($data, ['guard' => false]);
}

$this->Posts->save($post);

```

If i translate the Posts : **OK**  
If i translate the Metas : **OK**  
But if i translate Posts-\>Metas : **No**

Do you have a trick for my request 😉 ?

Thx everyone
