yii2-translateable icon indicating copy to clipboard operation
yii2-translateable copied to clipboard

After upgrading Yii to version 2.0.14 creating new translations not working

Open kadarpeter opened this issue 6 years ago • 5 comments

Before Yii version 2.0.14, the following code works well:

class PostController extends Controller
{
    public function actionCreate()
    {
        $model = new Post();

        foreach (Yii::$app->request->post('PostTranslation', []) as $language => $data) {
            foreach ($data as $attribute => $translation) {
                $model->translate($language)->$attribute = $translation;
            }
        }

        //...
    }

After upgrading Yii to version 2.0.14, the above code does not working. The related records in the post_translation table are not created. If I update the newly created post record, the translations are created in the post_translation table.

kadarpeter avatar Mar 04 '18 12:03 kadarpeter

Next algorithm works too

$template = new EmailTemplate();
$template->key = 'test';

$translation = $template->getTranslation('en');
$translation->subject = 'subject test';
$translation->body = 'body test';
$translation->hint = 'hint test';

$template->save();
$template->link('translations', $translation);

cc @kadarpeter

greeflas avatar Mar 04 '18 16:03 greeflas

@creocoder I created pull request with fix of this issue. Can you check it, please?

greeflas avatar Mar 12 '18 18:03 greeflas

Here is available supported new translatable behavior extension. Try it :) https://github.com/yiimaker/yii2-translatable

cc @kadarpeter @alex2549

greeflas avatar Apr 22 '18 13:04 greeflas

@greeflas Thank YOU A LOT! Cause I faced that problem today as well, so your https://github.com/yiimaker/yii2-translatable behavior save me. Only one thing I ask you to add in your repo is instruction with migration example, that would help new users how to use it as well as it's done by @creocoder.

alexanderYakovenkoUkr avatar Jul 04 '18 11:07 alexanderYakovenkoUkr

@SanChes-tanker Yes, I can. Please create an issue for this.

greeflas avatar Jul 04 '18 11:07 greeflas