Skip to content

Commit 5e7acc0

Browse files
dev
1 parent 8edfa0f commit 5e7acc0

File tree

3 files changed

+55
-10
lines changed

3 files changed

+55
-10
lines changed

README.md

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Component for multilingual site
22
================
33

4-
[<img src="https://skeeks.com/uploads/all/20/9e/a0/209ea08c3331e48573e6acbff8981990.png" alt="SkeekS blog" width="200"/>](https://skeeks.com/blog/programming/397-kak-preobrazovat-neaktivnye-ssylki-v-tekste-v-aktivnye-klikabelnye)
4+
[<img src="https://skeeks.com/uploads/all/4c/fd/50/4cfd50a535aef7c753b12c4adfbc0e33.png" alt="SkeekS blog" width="200"/>](https://skeeks.com/blog/programming/397-kak-preobrazovat-neaktivnye-ssylki-v-tekste-v-aktivnye-klikabelnye)
55

66
[![Latest Stable Version](https://poser.pugx.org/skeeks/yii2-multi-language/v/stable.png)](https://packagist.org/packages/skeeks/yii2-multi-language)
77
[![Total Downloads](https://poser.pugx.org/skeeks/yii2-multi-language/downloads.png)](https://packagist.org/packages/skeeks/yii2-multi-language)
@@ -24,20 +24,41 @@ Or add this to your `composer.json` file:
2424
}
2525
```
2626

27-
Use
27+
Use config your application
2828
-----
2929

30-
30+
```php
31+
32+
"bootstrap" => ["multiLanguage"],
33+
34+
"components" => [
35+
36+
"request" => [
37+
"class" => \skeeks\yii2\multiLanguage\MultiLangRequest::class
38+
],
39+
40+
"urlManager" => [
41+
"class" => \skeeks\yii2\multiLanguage\MultiLangUrlManager::class,
42+
'enablePrettyUrl' => true,
43+
'showScriptName' => false,
44+
],
45+
46+
"multiLanguage" => [
47+
"class" => \skeeks\yii2\multiLanguage\MultiLangComponent::class,
48+
'langs' => ['ru', 'en'],
49+
'default_lang' => 'ru',
50+
'lang_param_name' => 'lang',
51+
]
52+
53+
]
54+
```
3155
Screenshot
3256
----------
3357

34-
[<img src="https://skeeks.com/uploads/all/7c/cb/dc/7ccbdc8a1393cdb88d87635b610fb108.png" alt="SkeekS blog" width="600"/>](https://skeeks.com/uploads/all/7c/cb/dc/7ccbdc8a1393cdb88d87635b610fb108.png)
35-
3658

3759
Video
3860
-----
3961

40-
[<img src="https://skeeks.com/uploads/all/e4/cf/10/e4cf1067b25a0ca815ea2c82b5703e71.png" alt="Video" width="557"/>](https://youtu.be/lzmuahaNwQQ)
4162

4263
Links
4364
----------

src/MultiLangRequest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,15 @@ public function getUrl()
7474
}
7575

7676

77+
public $hostInfoNoLang = "";
78+
7779
/**
7880
* @return null|string
7981
*/
8082
public function getHostInfo()
8183
{
8284
$hostInfo = parent::getHostInfo();
85+
$this->hostInfoNoLang = $hostInfo;
8386

8487
if ($this->_lang_from_url) {
8588
$hostInfo = $hostInfo . "/" . $this->_lang_from_url;

src/MultiLangUrlManager.php

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,17 +54,20 @@ public function createUrl($params)
5454
//Получаем сформированный URL(без префикса идентификатора языка)
5555
$url = parent::createUrl($params);
5656

57-
/*print_r($lang);
58-
print_r($url);*/
59-
57+
/*print_r($lang);
58+
echo "\n";
59+
print_r($url);
60+
echo "\n";
61+
echo "\n";
62+
echo "\n";*/
6063
//Url absolute
6164
if (strpos($url, '://') !== false) {
6265
$urlData = parse_url($url);
6366
$path = ArrayHelper::getValue($urlData, 'path');
6467
if ($path == "/") {
6568
$path = "";
6669
}
67-
$urlData['path'] = "/".$lang.$path;
70+
$urlData['path'] = "/" . $lang . $path;
6871
return $this->unparse_url($urlData);
6972
} else if (strpos($url, '//') !== false) {
7073
$urlData = parse_url($url);
@@ -90,6 +93,24 @@ public function createUrl($params)
9093
}
9194
}
9295

96+
/**
97+
* @param array|string $params
98+
* @param null $scheme
99+
* @return string
100+
*/
101+
public function createAbsoluteUrl($params, $scheme = null)
102+
{
103+
$tmpHostInfo = $this->hostInfo;
104+
$request = \Yii::$app->request;
105+
if ($request instanceof MultiLangRequest) {
106+
$request->getHostInfo();
107+
$this->hostInfo = $request->hostInfoNoLang;
108+
}
109+
$url = parent::createAbsoluteUrl($params, $scheme);
110+
$this->hostInfo = $tmpHostInfo;
111+
return $url;
112+
}
113+
93114
/**
94115
* @param $parsed_url
95116
* @return string

0 commit comments

Comments
 (0)