For changing the language I tried protected/config/main.php

I inserted 



  It is working fine.

But I want to change the language through controller in components while logging into the main account through "UserIdentity"

    I tried Yii::app()-> setLanguage('en_ch');

but its not reflecting the change inside the application.

Are you sure the setLanguage() part gets called inside of your script? I think normally it should work that way.

Also check out this cookbook.

You need to write code to maintain the language across the application if you are only setting it in one controller.

Can you please tell us how to do it?

I am also facing same problem, it will be good if you explain it in detail.

Thank you

Hi all,

I got the solution to make it working, its just modification to the CookBook article mentioned by Y!!.

To get it working I added


   Yii::app()->session['_lang'] = 'en_ch';


in my UserIdentity.php after successful login.

And in all controllers we need to write init() function as -


    function init()


        $app = Yii::app();

        if (isset($app->session['_lang']))


            // set the application language to specific language

            $app->language = $app->session['_lang'];


        else {

           // set the application language to default if _lang var is not in the session

            $app->language = 'en_us';




Thanks for the help!

Hey dude,

This one really works…Thnks a lot

hey I do have one more query…

       Can anyone tell me how we can change the language of the validation errors.

   I want to change the complete sentence into any other language and this should be generic

When defining a validation rule, you can also define the error message for that rule.

array('username', 'length', 'min'=>3, 'max'=>12, 'tooShort' => Yii::t('username is too short'), 'tooLong' => Yii::t('username is to long')),

You can find all possible cases (like "tooLong") for each validator at the class reference.

array('username', 'length', 'min'=>3, 'max'=>12, 'tooShort' => Yii::t('username is too short'), 'tooLong' => Yii::t('username is to long')),

I tried this but im getting an error as "Missing argument 2 for YiiBase::t(), called in E:\shailendra\mywork\myproject\protected\models\modelname.php"

Earlier it was working fine with following

array('username', 'length', 'min'=>3, 'max'=>12)

Ok I got it… it requires the category field in it…

     Its working now but i m not getting all possible cases.....can u just give me the exact link.

And one more thing that how we are going to change the language of the instructions like for validation error there is one message

"Please fix the following input errors:"

Do we need to overwrite some functions or what???

On this page are all validators listed with links to each class reference.

Check out CHtml::errorSummary(). You can do this:

<?php echo CHtml::errorSummary($post, "<b>" . Yii::t('Fix input errors:') . "</b>"); ?>