@@ -15,24 +15,24 @@ class UriTranslationMacro
15
15
*/
16
16
public static function register ()
17
17
{
18
- Lang::macro ('uri ' , function ($ uri , $ locale = null ) {
18
+ Lang::macro ('uri ' , function ($ uri , $ locale = null , $ namespace = null ) {
19
19
20
20
// Attempt to translate full uri.
21
- if (!Str::contains ($ uri , '{ ' ) && Lang::has ("routes. $ uri " , $ locale )) {
22
- return Lang::get ("routes. $ uri " , [], $ locale );
21
+ if (!Str::contains ($ uri , '{ ' ) && Lang::has (( $ namespace ? $ namespace . ' :: ' : '' ). "routes. $ uri " , $ locale )) {
22
+ return Lang::get (( $ namespace ? $ namespace . ' :: ' : '' ). "routes. $ uri " , [], $ locale );
23
23
}
24
24
25
25
// Split the URI into a Collection of segments.
26
26
$ segments = new Collection (explode ('/ ' , trim ($ uri , '/ ' )));
27
27
28
28
// Attempt to translate each segment. If there is no translation
29
29
// for a specific segment, then its original value will be used.
30
- $ translations = $ segments ->map (function ($ segment ) use ($ locale ) {
31
- $ translationKey = "routes. {$ segment }" ;
30
+ $ translations = $ segments ->map (function ($ segment ) use ($ locale, $ namespace ) {
31
+ $ translationKey = ( $ namespace ? $ namespace . ' :: ' : '' ). "routes. {$ segment }" ;
32
32
33
33
// If the segment is not a placeholder and the segment
34
34
// has a translation, then update the segment.
35
- if ( ! Str::startsWith ($ segment , '{ ' ) && Lang::has ($ translationKey , $ locale )) {
35
+ if (! Str::startsWith ($ segment , '{ ' ) && Lang::has ($ translationKey , $ locale )) {
36
36
$ segment = Lang::get ($ translationKey , [], $ locale );
37
37
}
38
38
0 commit comments