Difference between #70 and #71 of
Yii v2 snippet guide

Revision #71 has been created by rackycz on Sep 20, 2019, 2:58:47 PM with the memo:

edit
« previous (#70) next (#72) »

Changes

Title unchanged

Yii v2 for beginners

Category unchanged

Tutorials

Yii version unchanged

2.0

Tags unchanged

tutorial,beginner,yii2

Content changed

[...]
// ... other configs
```

Switching languages + session + dropdown in the top menu
---
First lets add to file config/
web.php one moreparams.php attributes with list of supported languages: ```php aa
 
// config/web.php
 
$config = [
 
    // use your language
 
    // also accessible via Yii::$app->language
 
    'language' => 'cs-CZ'

 
<?php
 
return [
 
    // ...
 
    'allowedLanguages' => [
 
        'en-US' => "English",
 
        'cs-CZ' => "Česky"
, ], // This attribut'langSwitchUrl' => '/site/set-lang',
 
];
 
 
```
 
 
This list can b
e dis not necessary.
 
    // en-US is default value
 
    'sourceLanguage' => 'en-US',
 
played in the main menu. Edit file:
 
 
- C:\xampp\htdocs\basic\views\layouts\main.php
 
 
And above the Nav::widget add few rows:
 
 
```php
 
    $listOfLanguages = [];
 
    $langSwitchUrl = Yii::$app->params["langSwitchUrl"];
 
    foreach (Yii::$app->params["allowedLanguages"] as $langId => $langName) {
 'allowedLanguages' => ['en-US', 'cs-CZ'],   $listOfLanguages[] = ['label' => Yii::t('app', $langName), 'url' => [$langSwitchUrl, 'langID' => $langId]]; }     // ... other configs```
 
 
and then add one item into Nav::widge
 
 
```php
 
    echo Nav::widget([
 
        // ...
 
        'items' => [
 
            // ...
 
            ['label' => Yii::t('app', 'Language'),'items' => $listOfLanguages],
 
            // ...
```
 
Access rights --- ... text ...
7 0
4 followers
Viewed: 254 418 times
Version: 2.0
Category: Tutorials
Written by: rackycz
Last updated by: rackycz
Created on: Sep 19, 2019
Last updated: 5 months ago
Update Article

Revisions

View all history