Set global language value in Yii2 application

bxN5 picture bxN5 · Jan 10, 2015 · Viewed 34.1k times · Source

Where can I set language (based on user's cookie) globally? How to make it work in the whole application (controllers,views, etc.) ?

In documentation I found \Yii::$app->language = ''; but, where I can write my logic to change the language in right way?

Answer

Jelmer Keij picture Jelmer Keij · May 13, 2015

You can set your base language in the configuration file. In the basic application it's default location is: /config/web.php, in advanced: application-name/config/main.php and application-name/config/main-local.php.

$config = [
    'id' => 'basic',
    'language' => 'nl', // Set the language here
    'basePath' => dirname( __DIR__ ),
    'bootstrap' => ['log'],
    ...
];