protected function redirectToLanguage($language)
{
$result = parent::parseRequest($this->_request);
if ($result === false) {
throw new \yii\web\NotFoundHttpException(Yii::t('yii', 'Page not found.'));
}
list($route, $params) = $result;
if ($language) {
$params[$this->languageParam] = $language;
}
// See Yii Issues #8291 and #9161:
$params = $params + $this->_request->getQueryParams();
array_unshift($params, $route);
$url = $this->createUrl($params);
// Required to prevent double slashes on generated URLs
if ($this->suffix === '/' && $route === '') {
$url = rtrim($url, '/') . '/';
}
Yii::trace("Redirecting to {$url}.", __METHOD__);
Yii::$app->getResponse()->redirect($url);
if (YII2_LOCALEURLS_TEST) {
// Response::redirect($url) above will call `Url::to()` internally. So to really
// test for the same final redirect URL here, we need to call Url::to(), too.
throw new \yii\base\Exception(\yii\helpers\Url::to($url));
} else {
Yii::$app->end();
}
}