Ejemplo n.º 1
0
 /** @inheritdoc */
 public function createUrl($params)
 {
     $params = (array) $params;
     if (array_key_exists($this->languageParam, $params)) {
         $language = Language::fromAlias($params[$this->languageParam]) ?: Language::getDefault();
     } else {
         $language = Language::fromLocal(\Yii::$app->language) ?: Language::getDefault();
     }
     $params[$this->languageParam] = $language->alias;
     if (!$this->showDefaultLanguage && $language->alias === Language::getDefault()->alias) {
         unset($params[$this->languageParam]);
     }
     return parent::createUrl($params);
 }
Ejemplo n.º 2
0
 /** @inheritdoc */
 public function bootstrap($app)
 {
     if ($this->enableOverrideUrlManager) {
         $this->classMap[BaseUrlManager::class] = ['class' => UrlManager::class, 'languageParam' => $this->languageParam, 'showDefaultLanguage' => $this->showDefaultLanguage];
     }
     foreach ($this->classMap as $class => $definition) {
         \Yii::$container->set($class, $definition);
     }
     if (Language::getDefault()) {
         \Yii::$app->sourceLanguage = Language::getDefault()->local;
     }
     if (!isset($app->get('i18n')->translations[Module::$moduleName . '*'])) {
         $app->get('i18n')->translations[Module::$moduleName . '*'] = ['class' => PhpMessageSource::class, 'basePath' => __DIR__ . '/messages'];
     }
 }