OmgDef / yii2-multilingual-behavior

Yii2 port of the yii-multilingual-behavior.
146 stars 60 forks source link

Problem updating one of the languages #11

Closed fernandobatistapt closed 9 years ago

fernandobatistapt commented 9 years ago

Hi @OmgDef

I used your multilingual behaviour to create a form for multiple languages dynamically. 'languages' => ['pt' => 'Português', 'fr' => 'Français', 'en' => 'English', 'ru'=>'Russian']

This is my array, and the multilingual behavior is only updating PT and RU. PT however is my default language and if I switch EN to the last position of the array, it works...

My POST is correct and if I load the model and change a specific title manually and save() it works. ie: $model->title_en = 'changed in view'; $model->save();

I'm loading the values with the default $model->load(\Yii::$app->request->post()). Is that an issue? I noticed that in saveTranslations() in MultilingualBehavior, getLangAttribute($attribute . "_" . $lang); returns empty for all languages except for the default language and the one in the last position of the array.

Here follows my model configuration

public function behaviors() {
        return [
            'ml' => [
                'class' => MultilingualBehavior::className(),
                'languages' => \Yii::$app->params['languages'],
                'languageField' => 'lang',
                'dynamicLangClass' => true,
                'defaultLanguage' => \Yii::$app->params['defaultLanguage'],
                'langForeignKey' => 'id_product',
                'tableName' => "{{%shop_products_lang}}",
                'attributes' => [
                    'title', 'description', 'image', 'file', 'is_highlighted', 'is_visib'
                ]
            ],
        ];
    }

    public static function find() {
        /*
          $q = new MultilingualQuery(get_called_class());
          $q->localized();
          return $q;
         */
        return new MultilingualQuery(get_called_class());
    }

Is this a bug?

Thanks for any help.

OmgDef commented 9 years ago

@fernandobatistapt Thanks for feedback! It's a bug. Fixed in a05ac199590510a3d6d496fa38db6146d325f4ce

fernandobatistapt commented 9 years ago

@OmgDef thanks for the fix