9
9
10
10
/**
11
11
* @param mixed $page
12
- * @param string $text
13
12
* @param ?string $current_locale
14
13
* @return string The translated text if found, else returns the same given $text
15
14
*/
@@ -29,8 +28,6 @@ function current_path_locale($page): string
29
28
{
30
29
$ path = trim ($ page ->getPath (), '/ ' );
31
30
32
- $ default_locale = $ page ->defaultLocale ?? packageDefaultLocale ();
33
-
34
31
/**
35
32
* - [a-z]{2,3} language code
36
33
* - [A-Z]{2} region code
@@ -41,12 +38,12 @@ function current_path_locale($page): string
41
38
42
39
preg_match ($ locale_regex , $ path , $ matches );
43
40
44
- return $ matches ['locale ' ] ?? $ default_locale ;
41
+ return $ matches ['locale ' ] ?? packageDefaultLocale () ;
45
42
}
46
43
47
44
/**
48
45
* @param mixed $page
49
- * @param ?string $target_locale set to the default locale if null
46
+ * @param ?string $target_locale set to the default locale if null
50
47
* @return string Places $target_locale code in the current path
51
48
*/
52
49
function translate_path ($ page , ?string $ target_locale = null ): string
@@ -56,19 +53,19 @@ function translate_path($page, ?string $target_locale = null): string
56
53
$ current_locale = current_path_locale ($ page );
57
54
58
55
$ partial_path = match (true ) {
59
- $ current_locale === $ page-> defaultLocale => $ page ->getPath (),
56
+ $ current_locale === packageDefaultLocale ( $ page) => $ page ->getPath (),
60
57
default => substr ($ page ->getPath (), strlen ($ current_locale ) + 1 ),
61
58
};
62
59
63
60
return match (true ) {
64
- $ target_locale === $ page-> defaultLocale => "{$ partial_path }" ,
61
+ $ target_locale === packageDefaultLocale ( $ page) => "{$ partial_path }" ,
65
62
default => "/ {$ target_locale }{$ partial_path }" ,
66
63
};
67
64
}
68
65
69
66
/**
70
67
* @param mixed $page
71
- * @param ?string $target_locale set to the default locale if null
68
+ * @param ?string $target_locale set to the default locale if null
72
69
* @return string Places $target_locale code in the current url
73
70
*/
74
71
function translate_url ($ page , ?string $ target_locale = null ): string
@@ -78,8 +75,8 @@ function translate_url($page, ?string $target_locale = null): string
78
75
79
76
/**
80
77
* @param mixed $page
81
- * @param string $partial_path A path without the language prefix
82
- * @param ?string $target_locale uses the default locale if null
78
+ * @param string $partial_path A path without the language prefix
79
+ * @param ?string $target_locale uses the default locale if null
83
80
* @return string A path on the target locale
84
81
*/
85
82
function locale_path ($ page , string $ partial_path , ?string $ target_locale = null ): string
@@ -89,15 +86,15 @@ function locale_path($page, string $partial_path, ?string $target_locale = null)
89
86
$ partial_path = '/ ' .trim ($ partial_path , '/ ' );
90
87
91
88
return match (true ) {
92
- $ target_locale === $ page-> defaultLocale => $ partial_path ,
89
+ $ target_locale === packageDefaultLocale ( $ page) => $ partial_path ,
93
90
default => "/ {$ target_locale }{$ partial_path }"
94
91
};
95
92
}
96
93
97
94
/**
98
95
* @param mixed $page
99
- * @param string $partial_path A path without the language prefix
100
- * @param ?string $target_locale uses the default locale if null
96
+ * @param string $partial_path A path without the language prefix
97
+ * @param ?string $target_locale uses the default locale if null
101
98
* @return string A URL on the target locale
102
99
*/
103
100
function locale_url ($ page , string $ partial_path , ?string $ target_locale = null ): string
0 commit comments