48 lines
1.4 KiB
PHP
48 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace backend\modules\user;
|
|
|
|
use Yii;
|
|
use yii\web\Application;
|
|
use yii\i18n\PhpMessageSource;
|
|
use yii\base\BootstrapInterface;
|
|
|
|
class Module extends yii\base\Module implements BootstrapInterface
|
|
{
|
|
public $controllerNamespace = 'backend\modules\user\controllers';
|
|
|
|
public function init()
|
|
{
|
|
parent::init();
|
|
$this->registerTranslations();
|
|
}
|
|
|
|
public function registerTranslations()
|
|
{
|
|
Yii::$app->i18n->translations['user*'] = [
|
|
'class' => PhpMessageSource::class,
|
|
'sourceLanguage' => 'ru-RU',
|
|
'basePath' => '@backend/modules/user/messages',
|
|
'fileMap' => [
|
|
'user' => 'user.php',
|
|
],
|
|
];
|
|
}
|
|
|
|
public static function t($category, $message, $params = [], $language = null): string
|
|
{
|
|
return Yii::t('user' . $category, $message, $params, $language);
|
|
}
|
|
|
|
public function bootstrap($app)
|
|
{
|
|
if ($app instanceof Application) {
|
|
$app->getUrlManager()->addRules([
|
|
['class' => 'yii\web\UrlRule', 'pattern' => $this->id, 'route' => $this->id . '/default/index'],
|
|
['class' => 'yii\web\UrlRule', 'pattern' => $this->id . '<id:\w+>', 'route' => $this->id . '/default/view'],
|
|
['class' => 'yii\web\UrlRule', 'pattern' => $this->id . '<controller:[\w\-]+>/<action:[\w\-]+>', 'route' => $this->id . '/<controller>/<action>'],
|
|
], false);
|
|
}
|
|
}
|
|
}
|