@@ -10,6 +10,10 @@ make the value available to the rest of your application. Its callback hook
10
10
offers a convenient way to initialize other libraries or execute code based on
11
11
the locale value.
12
12
13
+ ## Installation
14
+
15
+ composer require boronczyk/localization-middleware
16
+
13
17
## Basic Example
14
18
15
19
use Boronczyk\LocalizationMiddleware;
@@ -33,10 +37,10 @@ the locale value.
33
37
$middleware = new LocalizationMiddleware($availableLocales, $defaultLocale);
34
38
35
39
$middleware->setSearchOrder([
36
- LocationMiddleware ::FROM_URI_PATH,
37
- LocationMiddleware ::FROM_URI_PARAM,
38
- LocationMiddleware ::FROM_COOKIE,
39
- LocationMiddleware ::FROM_HEADER
40
+ LocalizationMiddleware ::FROM_URI_PATH,
41
+ LocalizationMiddleware ::FROM_URI_PARAM,
42
+ LocalizationMiddleware ::FROM_COOKIE,
43
+ LocalizationMiddleware ::FROM_HEADER
40
44
]);
41
45
$middleware->setCallback(function (string $locale) {
42
46
putenv("LANG=$locale");
@@ -78,36 +82,36 @@ methods:
78
82
Sets the order in which inputs are searched for a suitable locale.
79
83
80
84
$middleware->setSearchOrder([
81
- LocationMiddleware ::FROM_URI_PATH,
82
- LocationMiddleware ::FROM_URI_PARAM,
83
- LocationMiddleware ::FROM_COOKIE,
84
- LocationMiddleware ::FROM_HEADER
85
+ LocalizationMiddleware ::FROM_URI_PATH,
86
+ LocalizationMiddleware ::FROM_URI_PARAM,
87
+ LocalizationMiddleware ::FROM_COOKIE,
88
+ LocalizationMiddleware ::FROM_HEADER
85
89
]);
86
90
87
91
Adding or removing locale sources from the order modifies the search
88
92
domain.
89
93
90
94
// only search cookies and the Accept-Language header
91
95
$middleware->setSearchOrder([
92
- LocationMiddleware ::FROM_COOKIE,
93
- LocationMiddleware ::FROM_HEADER
96
+ LocalizationMiddleware ::FROM_COOKIE,
97
+ LocalizationMiddleware ::FROM_HEADER
94
98
]);
95
99
96
100
The available local source constants are:
97
101
98
- * ` LocationMiddleware ::FROM_URI_PATH`
102
+ * ` LocalizationMiddleware ::FROM_URI_PATH`
99
103
Search for the locale in the URI path. The first directory value in
100
- the request path is considered the locale, for example
104
+ the request path is considered the locale, for example
101
105
` https://example.com/en_US/foo ` .
102
106
103
- * ` LocationMiddleware ::FROM_URI_PARAM`
107
+ * ` LocalizationMiddleware ::FROM_URI_PARAM`
104
108
Search for the locale in the URI parameter (the default parameter name
105
109
is ` locale ` ).
106
110
107
- * ` LocationMiddleware ::FROM_COOKIE`
111
+ * ` LocalizationMiddleware ::FROM_COOKIE`
108
112
Search for the locale in cookies (the default cookie name is ` locale ` ).
109
113
110
- * ` LocationMiddleware ::FROM_HEADER`
114
+ * ` LocalizationMiddleware ::FROM_HEADER`
111
115
Search for the local in the HTTP ` Accept-Language ` header. Header
112
116
searches make a best-effort search for locales, languages, and possible
113
117
quality modifiers.
@@ -153,7 +157,7 @@ methods:
153
157
154
158
* ` setCallback(callable $func) `
155
159
Sets a callback that is invoked after the middleware identifies the locale,
156
- offering the developer a chance to conveniently initialize other libraries
160
+ offering the developer a chance to conveniently initialize other libraries
157
161
or execute other code with the value. The callable’s signature is:
158
162
` function (string $locale) ` .
159
163
@@ -167,4 +171,4 @@ methods:
167
171
168
172
169
173
## License
170
- [ ![ FOSSA Status] ( https://app.fossa.io/api/projects/git%2Bhttps%3A%2F%2Fgithub.heygears.com%2Ftboronczyk%2Flocalization-middleware.svg?type=large )] ( https://app.fossa.io/projects/git%2Bhttps%3A%2F%2Fgithub.heygears.com%2Ftboronczyk%2Flocalization-middleware?ref=badge_large )
174
+ [ ![ FOSSA Status] ( https://app.fossa.io/api/projects/git%2Bhttps%3A%2F%2Fgithub.heygears.com%2Ftboronczyk%2Flocalization-middleware.svg?type=large )] ( https://app.fossa.io/projects/git%2Bhttps%3A%2F%2Fgithub.heygears.com%2Ftboronczyk%2Flocalization-middleware?ref=badge_large )
0 commit comments