Yii v2 snippet guide III

Comparing #4 with #5

Revision #5 was created by rackycz rackycz on Jan 21, 2021, 2:29:31 PM.

Translations

Content

# Switching languages and Language in URL I already [wrote](https://www.yiiframework.com/wiki/2552/yii-v2-snippet-guide#i18n-translations) how translations work. Here I will show how language can be switched and saved into the URL. So let's add the language switcher into the main menu:
 
```php
echo Nav::widget([
'options' => ['class' => 'navbar-nav navbar-right'],
[...]
]
```

 
Now we need to process the new GET parameter and save it to Session in order to keep the new language. Best is to create a BaseController which will be extended by all controllers. Its content looks like this:
 
```php
<?php
namespace app\controllers;
use yii\web\Controller;
class _BaseController extends Controller {
public function beforeAction($action) {
[...]