Yii’s I18n topic isn’t enough for me.
My source lang is Turkish , target lang is English (for example)
My test controller’s index action :
public function actionIndex()
{
Yii::app()->language='en';
$this->render("index");
}
This is my view file’s content :
echo Yii::t('test', 'Deneme');
And lastly, this is my protected/messages/en/test.php file’s content:
return array(
'Deneme' => 'Example',
);
Everything OK, it’s returning Example . But as you can see, i’m setting language manually on my index action. How can i do it automatically ? Must i add Yii::app()->language=’en’; to all actions? How you are using l18n on your projects ?
Note : I’m Yii and l18n noob, so please describe step by step .
Thank you.
You should set the target language in
CWebApplication:beginRequest()in
protected/config/main.php, add:In protected/components, create a file
MyApp.php, and add this class:Remember to declare
beginRequest()asstatic, or you will encounter errors like this:https://github.com/yiisoft/yii/issues/794