Blame view

protected/components/Application.php 1.14 KB
a1684257   Administrator   first commit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
  <?php
  
  class Application extends CWebApplication
  {
      public function init()
      {
          $app = $this;
          preg_match("#^(en|ru)#", $app->request->pathInfo, $langMatches);
          if (0 != count($langMatches)) { // set language from `lang` param
              if (count(array_intersect(array($langMatches[0]), Yii::app()->params['languages'])) == 0)
                  $this->request->redirect('/');
              $app->language = $langMatches[0];
              $app->request->cookies['lang'] = new CHttpCookie('lang', Yii::app()->language);
          } else if (isset($app->request->cookies['lang'])) { // set last remembered language
              $app->language = $app->request->cookies['lang']->value;
          } else {
              // todo: set language by request headers
              // $al =  $_SERVER["HTTP_ACCEPT_LANGUAGE"];
          }
          parent::init();
  
          // todo: warning! remove this handler on production(after messages translation complete).
          Yii::app()->messages->onMissingTranslation = array(new MissingTranslationEventHandler(), 'missingTranslation');
          Yii::app()->messages->forceTranslation = true; // allow ru->ru translation
      }
  }