Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

YII Change the default language

Tags:

php

yii

I'm a beginner in YII framework (PHP) When creating a new site with YII, it will displayed with english page.

I want to change the default language to French, so pages will be displayed in French.

like image 259
user1288058 Avatar asked Sep 15 '12 18:09

user1288058


2 Answers

To change the language, set CApplication::language appropriately. This can be done at runtime as in

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

but usually it's done in your application configuration:

array(
    // ...settings...
    'language' => 'fr',
    // ...more settings...
)
like image 170
Jon Avatar answered Oct 20 '22 16:10

Jon


and so you can set the default languages in the config/main.php as

return array(
    ...
    'sourceLanguage' => 'fr',
    'language'=>'en',
    ...
    'params' => array(
               ...
               'languages'=>array('en_us'=>'English', 'fr'=>'French', 'fa_ir'=>'فارسی'),
               ....
               ), 
); 

and change your language everywhere you like:

Yii::app()->language = Yii::app()->params->languages['fa_ir'];

or more:

Yii::app()->language = Yii::app()->params->languages[$_GET['lang']];
like image 30
shgnInc Avatar answered Oct 20 '22 15:10

shgnInc