Multilingual Support

Hi everyone!

I want to make my webite multilingual. For that I did the folowoing:

  1. Dropdownlist with languages. "On select" event the ChangeLanguage action is caled in the DefaultController:



class DefaultController extends Controller {

... 

   public function actionChangeLanguage()

    {

        if(isset($_POST['_lang']) && !empty($_POST['_lang'])) 

        {

            Yii::app()->setLanguage($_POST['_lang']);

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

            $this->redirect(Yii::app()->user->returnUrl);

        }

    }


...

}



  1. In the Controller which the DefaultController is extended from contains the following:



class Controller extends CController

{

...

	private $_pageKeywords;

	private $_pageDescription;


    function init()

    {

        parent::init();

        Yii::app()->setLanguage(isset(Yii::app()->session['_lang']) ? Yii::app()->session['_lang'] : Yii::app()->language); 

    } 

...



Then I choose a language (ex. English) in the select and:

  • Yii::app()->session[’_lang’] returns ‘en’

  • Yii::app()->language returns the app language set in protected\config\main.php




'language'=>'ru',



That is the application langues does not change and no translation is made with Yii:t unless I put in views\layouts\main.php the same code I have in function init() in the Controller:




<?php Yii::app()->setLanguage(isset(Yii::app()->session['_lang']) ? Yii::app()->session['_lang'] : Yii::app()->language); ?>



Please, help to understand why thy language is not set without that code in the main layout file?