title: Yii2 - Change Language
body: <p>I have a problem with my advanced template when I try to change page using internationalization.
  I try to explain. To use the internationalization on my site I have follow this steps:</p>
  
  <p>In params.php, I have added this:</p>
  
  <pre><code>&lt;?php
     return [
       'adminEmail' =&gt; 'admin@example.com',
       'languages' =&gt; [
       'en' =&gt; 'English',
       'it' =&gt; 'Italian',
      ],
    ];
  </code></pre>
  
  <p>I have added this in my frontend\views\layouts\main.php to call on my website the languages insert above:</p>
  
  <pre><code>&lt;?php 
     foreach(Yii::$app-&gt;params['languages'] as $key =&gt; $language){
     echo '&lt;span class="language" id ="'.$key.'"&gt;'.$language.' | &lt;/span&gt;';
     }
  ?&gt; 
  </code></pre>
  
  <p>after I have created a new file named main.js. To permit to yii2 to see the main.js file I added this in the AppAsset.php (is it correct?). In this file I insert this:</p>
  
  <pre><code>$(function(){
    $(document).on('click','.language', function(){
       var lang = $(this).attr('id');
       $.post('index.php?r=site/language', {'lang':lang},function(data){
      location.reload();  
    });
  }); 
  $(document).on('click','.fc-day', function(){
      var date = $(this).attr('data-date');       
          $get('index.php?r=event/create',{'date':date},function(data){
              $('#modal').modal(show)
              .find('#modalContent')
              .html(data);            
          });
  }); 
  
  $('#modalButton').click(function(){
          $('#modal').modal(show)
          .find('#modalContent')
          .load($(this).attr('value'));
  });
  }); 
  </code></pre>
  
  <p>after that in the sitecontroller.php I have added this:</p>
  
  <pre><code>public function actionLanguage()
  {
      if(isset($_POST['lang'])){
          Yii::$app-&gt;language = $_POST['lang'];
          $cookie = new Yii\web\cookie([
          'name'=&gt;'lang',
          'value'=&gt;$_POST['lang']
      ]);
      Yii::$app-&gt;getResponse()-&gt;getCookies()-&gt;add($cookie);
      }
  }
  </code></pre>
  
  <p>after in config\main.php I have added this in components:</p>
  
  <pre><code>'components' =&gt; [
      'i18n' =&gt; [
          'translations' =&gt; [
              'app' =&gt; [
                  'class' =&gt; 'yii\i18n\PhpMessageSource',
                  //'basepath' =&gt; @app/messages,
                  'sourceLanguage' =&gt; 'it',
                  'fileMap' =&gt; [
                      'app' =&gt; 'app.php', 
                      'app/error' =&gt; 'error.php',
                  ],
              ],
          ],
      ],
  </code></pre>
  
  <p>finally i have create on the root a folder called messages\it and messages\en and inside two files (one per folder) called app.php I have insert this text:</p>
  
  <pre><code>&lt;?php
     return [
        'Benvenuto' =&gt; 'Welcome'
     ];
  </code></pre>
  
  <p>that's all...but after load my home page (correctly) when i click on one of the languages (Italian or English) I see the following messages:</p>
  
  <p>jquery.js?ver=1.11.3:4 POST <a href="http://localhost/mdf/frontend/web/index.php?r=site/language" rel="nofollow noreferrer">http://localhost/mdf/frontend/web/index.php?r=site/language</a> 400 (Bad Request)</p>
  
  <p>And If I try to paste directly this url, I obtain only a blank page:
  <a href="http://localhost/mdf/frontend/web/index.php?r=site/language" rel="nofollow noreferrer">http://localhost/mdf/frontend/web/index.php?r=site/language</a></p>