Blame view

vendor/kartik-v/yii2-krajee-base/TranslationTrait.php 1.12 KB
583ea05f   andryeyev   + widget-select2
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
  <?php
  
  /**
   * @package   yii2-krajee-base
   * @author    Kartik Visweswaran <kartikv2@gmail.com>
   * @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2014 - 2015
   * @version   1.7.7
   */
  
  namespace kartik\base;
  
  use Yii;
  
  /**
   * Trait for all translations used in Krajee extensions
   *
   * @author Kartik Visweswaran <kartikv2@gmail.com>
   * @since 1.7.7
   */
  trait TranslationTrait
  {
      /**
       * Yii i18n messages configuration for generating translations
       *
       * @return void
       */
      public function initI18N($dir = '')
      {
          if (empty($this->_msgCat)) {
              return;
          }
          if (empty($dir)) {
              $reflector = new \ReflectionClass(get_class($this));
              $dir = dirname($reflector->getFileName());
          }
          Yii::setAlias("@{$this->_msgCat}", $dir);
          if (empty($this->i18n)) {
              $this->i18n = [
                  'class' => 'yii\i18n\PhpMessageSource',
                  'basePath' => "@{$this->_msgCat}/messages",
                  'forceTranslation' => true
              ];
          }
          Yii::$app->i18n->translations[$this->_msgCat . '*'] = $this->i18n;
      }
  }