Changing Language

I am a newbie to Yii and am in the process of developing a multilingual (English and French) website.

I tried what was suggested in the first post here:

[post='http://www.yiiframework.com/forum/index.php?/topic/6137-example-of-changing-language/ ']http://www.yiiframework.com/forum/index.php?/topic/6137-example-of-changing-language/ [/post]

It works exactly as intended (the French text is echoed) as long as I use


echo Yii::t('blog','Active record class "{class}" does not have a scope named "{scope}".');

in protected/views/layout/main.php. However, if I use the same line of code in a view, I get the English code instead. Furthermore, in the view, if I do


echo Yii::app()->getLanguage();

I get ‘en_us’.

Shouldn’t using


Yii::app()->setLanguage($lang);

in protected/views/layout/main.php affect the language in the view?

Thanks in advance for your help.

Note: I understand that if I want the user’s language to apply to there entire session I will need to store it in a session. For the moment, though, I am only trying to deal with one page load.

No, the view is rendered before the layout.

/Tommy

So where would be the best place to set the language then? It doesn’t seem very practical to have code to set it in each view.

You can change language e.g. in a controllers init method or in a base controller like in this wiki. Gii will generate a base controller named Controller in the protected/components folder.

/Tommy