-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBaseModule.php
executable file
·43 lines (39 loc) · 1.18 KB
/
BaseModule.php
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
<?php
namespace altiore\base;
use Yii;
use yii\base\Module;
use yii\helpers\ArrayHelper;
class BaseModule extends Module
{
public $msgCategoryName = 'altioreBase';
public function init()
{
parent::init();
$this->initI18N();
}
/**
* Yii i18n messages configuration for generating translations
*
* @return void
*/
public function initI18N()
{
$reflector = new \ReflectionClass(get_class($this));
$dir = dirname($reflector->getFileName());
$cat = $this->msgCategoryName;
Yii::setAlias("@{$cat}", $dir);
$config = [
'class' => 'yii\i18n\PhpMessageSource',
'basePath' => "@{$cat}/messages",
'forceTranslation' => true
];
$globalConfig = ArrayHelper::getValue(Yii::$app->i18n->translations, "{$cat}*", []);
if (!empty($globalConfig)) {
$config = array_merge($config, is_array($globalConfig) ? $globalConfig : (array) $globalConfig);
}
if (!empty($this->i18n) && is_array($this->i18n)) {
$config = array_merge($config, $this->i18n);
}
Yii::$app->i18n->translations["{$cat}*"] = $config;
}
}