How To Create Multilanguage Form In Yii

I have a directory within /protected/views/controller_Id/LanguageID_RegionID and placed second language view forms here.

Now how can i translated form elements(such as labels) to second language?

Hi,

First you can create the protected/messages/en_US/en.php

main .php


'language'=>'en_US',

and in en.php


return array (

  'Home222' => 'Home',

);

and finally you can write




Yii::t('Home', 'Home222');

How can translated form elements(such as labels) to second language?

For example if we have


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

how can translate the attribute label value to second language?

I found this way:


<?php echo $form->label($model,'name',array('label'=>Yii::t('text','name'))); ?>

This is a standard method?

And in attributeLabels() i used this way:




	public function attributeLabels()

	{

		return array(

        	. . . .

			'name' => Yii::t('form','name'),

        	. . . . 

		);

	}



Are these ways right? Please guide.

hi,

yes it’s no any issue but u can write every model so best idea is u can create a file and put your lable array when u traslate in this way u can change only one file

Best Regards,

Ankit Modi

what’s your mean?

Hi,

Means if u are translate all lable and then after if any changes are available so open a this all model and u can made all changes

but if u are not open to all model so u can open this only file and changes lable so apply this changes are all lable project.

Best Regards,

Ankit Modi