i18n according to user profile


I’d like to set the language of my application (i18n) according to the user profile but it doesn’t work. In the following excerpt, the profile is right and is stored in an array.

In UserIdentity, I have:

Yii::app()->language = $profile['language'];

I tried to force language to french:

Yii::app()->language = 'fr-fr';

I also tried to move this instruction to LoginForm.login() or SiteController.actionLogin() but without any success.

What’s wrong ? thank you,


Did you try ‘fr’?

Yii::app()->language = 'fr';


The value you set for CApplication::language has to match the name of the directory containing your messages or views. So take a look at what those are. The suggested convention in Yii is language-code userscore region-code, all in lowercase, e.g. ‘en_us’ or ‘fr_fr’. I’ve seen the language only without the underscore and region code, but a hyphen, as you used in ‘fr-fr’, is unconventional.

Thank you for your suggestions,

I finally solved my problem with a language init in the Controller:

class Controller extends CController {


    public function init(){

    	$app = Yii::app();


    		$app->language = $app->user->language;