Solved. Multilingual Models: Wrong Output Updating Model

Hi,

I’m trying to set up multilingual behavior in my demo project “Trackstar”. Model “Project” is only one using this behavior. There are two languages: english and lithuanian. Everything works ok, but when I try to update model,update form displays wrong text.

Example steps:

  1. Creaded new project english1 (defaultLanguage’=> ‘en’)

  2. Updated english1 to lithuanian1(defaultLanguage’=> ‘lt’)

  3. Switched back to english(sourceLanguage=>‘en’ and defaultLanguage’=> ‘en’)

In project listing see english1, project details also english1, but in update form lithuanian1

As I undersdand, update form this data gets from tbl_project, not from tbl_projectLang.

More details:

models/Project.php:


public function behaviors() {

    return array(

        'ml' => array(

            'class' => 'application.models.behaviours.MultilingualBehavior',

            'langClassName' => 'ProjectLang',

            'langTableName' => 'projectLang',

            'langForeignKey' => 'project_id',

            'langField' => 'lang_id',

            'localizedAttributes' => array('name', 'description'),

            'localizedPrefix' => 'l_',

            'languages' => Yii::app()->params['translatedLanguages'], // array('en'=>'english','lt'=>'lietuviu')

            'defaultLanguage' => Yii::app()->params['defaultLanguage'], //'en'

            'createScenario' => 'insert',

            'localizedRelation' => 'i18nProject',

            'multilangRelation' => 'multilangProject',

           // 'forceOverwrite' => false, 

            'forceDelete' => true, 

            //'dynamicLangClass' => true,

        ),

);

}




public function defaultScope()

{

    return $this->ml->localizedCriteria();

}


public function actionUpdate($id)

	{

		

		$model = $this->loadModel($id,true);

		if(isset($_POST['Project']))

		{	

			$model->attributes=$_POST['Project'];

			if($model->save())

				$this->redirect(array('view','id'=>$model->id));

		}


		$this->render('update',array(

			'model'=>$model,

		));

	}

views/project/update.php:


<?php echo $this->renderPartial('_form', array('model'=>$model)); ?>

views/project/_form.php:


<?php foreach (Yii::app()->params['translatedLanguages'] as $l => $lang) :

   if($l === Yii::app()->params['defaultLanguage']) $suffix = '';

    else $suffix = '_'.$l;

    endforeach; ?>

        

<div class="form">


<?php $form=$this->beginWidget('CActiveForm', array(

	'id'=>'project-form',

	'enableAjaxValidation'=>false,

)); ?>


	<p class="note">Fields with <span class="required">*</span> are required.</p>


	<?php echo $form->errorSummary($model); ?>


	<div class="row">

		<?php echo $form->labelEx($model,'name'); ?>

		<?php echo $form->textField($model,'name'.$suffix,array('size'=>60,'maxlength'=>255)); ?>

		<?php echo $form->error($model,'name'.$suffix); ?>

	</div>


	<div class="row">

		<?php echo $form->labelEx($model,'description'); ?>

		<?php echo $form->textArea($model,'description'.$suffix,array('rows'=>6, 'cols'=>50)); ?>

		<?php echo $form->error($model,'description'.$suffix); ?>

	</div>


	

	<div class="row buttons">

		<?php echo CHtml::submitButton($model->isNewRecord ? 'Create' : 'Save'); ?>

	</div>

<?php $this->endWidget(); ?>


</div><!-- form -->

what is the error?

Are you sure




Yii::app()->params['translatedLanguages'] and Yii::app()->params['translatedLanguages']



are set correctly in your code.Is it assigned with correct values. as per your code.Please check again with it. Might be you are there is some issue.

There are no any php errors. Main point is not correct data. If I create new project in english then update this project name and description in lithuanian and after that, want update this project in english, update form displays lithuanian data, not english. This is the problem.

my config/main.php seems to be ok


'params'=>array(

		'translatedLanguages'=>array('en'=>'english','lt'=>'lietuvių'),

		'defaultLanguage'=> 'en',

	),  

Ahh so you mean to say you have saved description and title in lithuanian language in database and now you want to retrieve it in English language. is it correct ???

Then i can suggest you a quick solution.

Well at the time of creating a project record. save this description and title in english and lithuanian in database in two different fields.

Then show the output according to the current selected language in form. and again do the same process for saving the data in update action.(Update both the field according to updated data in lithuanian and english).

Solved it. Sorry, this was my stupid mistake in Project controllers loadModel definition, witch made load project model incorrectly. Thanks for replies :rolleyes:

Glad to know ;)