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
|
|
|
* @return Illuminate\Contracts\Routing\UrlGenerator|string |
19
|
|
|
*/ |
20
|
|
|
function lang_url($path = null, $parameters = [], $secure = null) |
21
|
|
|
{ |
22
|
1 |
|
if (is_null($path)) { |
23
|
|
|
return app(Illuminate\Contracts\Routing\UrlGenerator::class); |
24
|
|
|
} |
25
|
|
|
|
26
|
1 |
|
$multilang = app('multilang'); |
27
|
|
|
|
28
|
1 |
|
$path = $multilang->getUrl($path); |
29
|
|
|
|
30
|
1 |
|
return url($path, $parameters, $secure); |
31
|
|
|
} |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
if (!function_exists('lang_redirect')) { |
35
|
|
|
/** |
36
|
|
|
* Get an instance of the redirector. |
37
|
|
|
* |
38
|
|
|
* @param string|null $to |
39
|
|
|
* @param int $status |
40
|
|
|
* @param array $headers |
41
|
|
|
* @param bool $secure |
42
|
|
|
* @return \Illuminate\Routing\Redirector|\Illuminate\Http\RedirectResponse |
43
|
|
|
*/ |
44
|
|
|
function lang_redirect($to = null, $status = 302, $headers = [], $secure = null) |
|
|
|
|
45
|
|
|
{ |
46
|
|
|
if (is_null($to)) { |
47
|
|
|
return app('redirect'); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
$multilang = app('multilang'); |
51
|
|
|
|
52
|
|
|
$to = $multilang->getUrl($to); |
53
|
|
|
|
54
|
|
|
return app('redirect')->to($to, $status, $headers, $secure); |
55
|
|
|
} |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
if (! function_exists('lang_route')) { |
59
|
|
|
/** |
60
|
|
|
* Get route by name |
61
|
|
|
* |
62
|
|
|
* @param string $name |
63
|
|
|
* @param array $parameters |
64
|
|
|
* @param bool $absolute |
65
|
|
|
* @return string |
66
|
|
|
*/ |
67
|
|
|
function lang_route($name, array $parameters = [], $absolute = true) |
68
|
|
|
{ |
69
|
|
|
$multilang = app('multilang'); |
70
|
|
|
|
71
|
|
|
$name = $multilang->getRoute($name); |
72
|
|
|
|
73
|
|
|
return app('url')->route($name, $parameters, $absolute); |
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
if (!function_exists('t')) { |
78
|
|
|
/** |
79
|
|
|
* Get translated text |
80
|
|
|
* |
81
|
|
|
* @param string $text |
82
|
|
|
* @param array $replace |
83
|
|
|
* @return string |
84
|
|
|
*/ |
85
|
|
|
function t($text, array $replace = []) |
86
|
|
|
{ |
87
|
1 |
|
$text = app('multilang')->get($text, $replace); |
88
|
|
|
|
89
|
1 |
|
return $text; |
90
|
|
|
} |
91
|
|
|
} |
92
|
|
|
|
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.