Change language in YII

后端 未结 3 1213
借酒劲吻你
借酒劲吻你 2021-01-23 02:47

After creating a new site with YII, I added a folder \'fr\' in protected/messages and added a file \'site.php\' which contains:

return array(\'hello\' =>

3条回答
  •  無奈伤痛
    2021-01-23 03:18

    You should set language in the controller if you want translations to work properly in all views.

    In order for language to be applied to all Controllers, create in components folder new Controller.php file with class Controller which extends CController, and then all your controllers should extend Controller class. in Controller class override init() method (don't forget to call parent::init()) and set language there. For example:

    class Controller extends CController
    {
        public $layout='//layouts/column1';
    
        function init()
        {
            parent::init();
            Yii::app()->language = 'fr';
        }
     }
    

    This way you can add additional things which should apply to all Controllers at one place

提交回复
热议问题