1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* This file is part of the Laravel MultiLang package. |
4
|
|
|
* |
5
|
|
|
* (c) Avtandil Kikabidze aka LONGMAN <[email protected]> |
6
|
|
|
* |
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
8
|
|
|
* file that was distributed with this source code. |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
if (! function_exists('lang_url')) { |
12
|
|
|
/** |
13
|
|
|
* Generate a url for the application. |
14
|
|
|
* |
15
|
|
|
* @param string $path |
16
|
|
|
* @param mixed $parameters |
17
|
|
|
* @param bool $secure |
18
|
|
|
* @param string $locale |
19
|
|
|
* @return Illuminate\Contracts\Routing\UrlGenerator|string |
20
|
|
|
*/ |
21
|
|
|
function lang_url($path = null, $parameters = [], $secure = null, $locale = null) |
22
|
|
|
{ |
23
|
2 |
|
if (is_null($path)) { |
24
|
1 |
|
return app(Illuminate\Contracts\Routing\UrlGenerator::class); |
25
|
|
|
} |
26
|
|
|
|
27
|
1 |
|
$multilang = app('multilang'); |
28
|
|
|
|
29
|
1 |
|
$path = $multilang->getUrl($path, $locale); |
30
|
|
|
|
31
|
1 |
|
return url($path, $parameters, $secure); |
32
|
|
|
} |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
if (! function_exists('lang_redirect')) { |
36
|
|
|
/** |
37
|
|
|
* Get an instance of the redirector. |
38
|
|
|
* |
39
|
|
|
* @param string|null $to |
40
|
|
|
* @param int $status |
41
|
|
|
* @param array $headers |
42
|
|
|
* @param bool $secure |
43
|
|
|
* @return \Illuminate\Routing\Redirector|\Illuminate\Http\RedirectResponse |
44
|
|
|
*/ |
45
|
|
|
function lang_redirect($to = null, $status = 302, $headers = [], $secure = null) |
|
|
|
|
46
|
|
|
{ |
47
|
2 |
|
if (is_null($to)) { |
48
|
1 |
|
return app('redirect'); |
49
|
|
|
} |
50
|
|
|
|
51
|
1 |
|
$multilang = app('multilang'); |
52
|
|
|
|
53
|
1 |
|
$to = $multilang->getUrl($to); |
54
|
|
|
|
55
|
1 |
|
return app('redirect')->to($to, $status, $headers, $secure); |
56
|
|
|
} |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
if (! function_exists('lang_route')) { |
60
|
|
|
/** |
61
|
|
|
* Get route by name |
62
|
|
|
* |
63
|
|
|
* @param string $name |
64
|
|
|
* @param array $parameters |
65
|
|
|
* @param bool $absolute |
66
|
|
|
* @return string |
67
|
|
|
*/ |
68
|
|
|
function lang_route($name, array $parameters = [], $absolute = true) |
69
|
|
|
{ |
70
|
1 |
|
$multilang = app('multilang'); |
71
|
|
|
|
72
|
1 |
|
$name = $multilang->getRoute($name); |
73
|
|
|
|
74
|
1 |
|
return app('url')->route($name, $parameters, $absolute); |
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
if (! function_exists('t')) { |
79
|
|
|
/** |
80
|
|
|
* Get translated text |
81
|
|
|
* |
82
|
|
|
* @param string $text |
83
|
|
|
* @param array $replace |
84
|
|
|
* @return string |
85
|
|
|
*/ |
86
|
|
|
function t($text, array $replace = []) |
87
|
|
|
{ |
88
|
1 |
|
$text = app('multilang')->get($text, $replace); |
89
|
|
|
|
90
|
1 |
|
return $text; |
91
|
|
|
} |
92
|
|
|
} |
93
|
|
|
|
Adding explicit visibility (
private
,protected
, orpublic
) is generally recommend to communicate to other developers how, and from where this method is intended to be used.