I want to create link to the currently visited page but change the application language.
For example I am on article page that is displaying one article on Italian language, and I want to allow users to change language to English but to stay on that article. How can I do this ?
I have tried this, but it is not working:
<?= HTML::a('en', UrlHelper::createLocalizedUrl('en'), ['class' => '']) ?>
public static function createLocalizedUrl($language)
{
$request = Yii::$app->request;
$pathInfo[] = $request->getPathInfo();
$params = $request->getQueryParams();
$url = array_push($pathInfo, $params);
Yii::$app->language = $language;
return $url;
}
I am also using https://github.com/codemix/yii2-localeurls
Any help please ? The way http://www.yiiframework.com/doc-2.0/yii-web-urlmanager.html#createUrl()-detail works, give me headache.