@@ -17,12 +17,12 @@ Automatically detect and set an app locale that matches your visitor's preferenc
17
17
- Uses the most common locale [ stores] ( #stores ) by default
18
18
- Easily create and add your own detectors and stores
19
19
20
- ## Requirements
20
+ ## ✅ Requirements
21
21
22
22
- PHP >= 7.1
23
23
- Laravel >= 5.6
24
24
25
- ## Install
25
+ ## 📦 Install
26
26
27
27
Install this package with Composer:
28
28
@@ -32,7 +32,7 @@ composer require codezero/laravel-localizer
32
32
33
33
Laravel will automatically register the ServiceProvider.
34
34
35
- ## Add Middleware
35
+ ## 🧩 Add Middleware
36
36
37
37
Add the middleware to the ` web ` middleware group in ` app/Http/Kernel.php ` .
38
38
Make sure to add it after ` StartSession ` and before ` SubstituteBindings ` :
@@ -65,7 +65,7 @@ protected $middlewarePriority = [
65
65
If you don't see the ` $middlewarePriority ` array in your kernel file,
66
66
then you can copy it over from the parent class ` Illuminate\Foundation\Http\Kernel ` .
67
67
68
- ## Configure
68
+ ## ⚙️ Configure
69
69
70
70
### Publish Configuration File
71
71
@@ -101,7 +101,7 @@ Or you can use one or more custom domains for a locale:
101
101
];
102
102
```
103
103
104
- ### Configure Detectors (optional)
104
+ ## 🔍 Detectors
105
105
106
106
By default, the middleware will use the following detectors to check for a supported locale in:
107
107
@@ -114,47 +114,118 @@ By default, the middleware will use the following detectors to check for a suppo
114
114
7 . The browser
115
115
8 . The app's default locale
116
116
117
- If you configure an omitted locale, no additional detectors will run after the ` OmittedLocaleDetector ` .
118
- This makes sense, because the locale will always be determined by the URL in this scenario.
119
-
120
- You can configure the route action, session key, cookie name and the attribute on the user model that holds the locale.
121
- By default this is all set to ` locale ` . If the user model does not have this attribute, it will skip this check.
122
-
123
- You can also choose which detectors to run and in what order.
117
+ Update the ` detectors ` array to choose which detectors to run and in what order.
124
118
125
119
> You can create your own detector by implementing the ` \CodeZero\Localizer\Detectors\Detector ` interface
126
120
> and add a reference to it in the config file. The detectors are resolved from Laravel's IOC container,
127
121
> so you can add any dependencies to your constructor.
128
122
129
- ### Configure Stores (optional)
123
+ ## 💾 Stores
130
124
131
125
The first supported locale that is returned by a detector will automatically be stored in:
132
126
133
127
- The session
134
128
- A cookie
135
129
- The app locale
136
130
137
- In the configuration file, you can choose which stores to use.
131
+ Update the ` stores ` array to choose which stores to use.
138
132
139
133
> You can create your own store by implementing the ` \CodeZero\Localizer\Stores\Store ` interface
140
134
> and add a reference to it in the config file. The stores are resolved from Laravel's IOC container,
141
135
> so you can add any dependencies to your constructor.
142
136
143
- ## Testing
137
+ ## 🛠️ More Configuration (optional)
138
+
139
+ ### ☑️ ` omit-locale `
140
+
141
+ If you don't want your main locale to have a slug, you can set it as the ` omit-locale ` (not the custom slug).
142
+ If you do this, no additional detectors will run after the ` UrlDetector ` and ` OmittedLocaleDetector ` .
143
+ This makes sense, because the locale will always be determined by those two in this scenario.
144
+
145
+ Example:
146
+
147
+ ``` php
148
+ 'omit-locale' => 'en',
149
+ ```
150
+
151
+ Result:
152
+
153
+ - /example-route (English without slug)
154
+ - /nl/example-route (Other locales with slug)
155
+
156
+ Default: ` null `
157
+
158
+ ### ☑️ ` trusted-detectors `
159
+
160
+ Add any detector class name to this array to make it trusted. (do not remove it from the ` detectors ` array)
161
+ When a trusted detector returns a locale, it will be used as the app locale, regardless if it's a supported locale or not.
162
+
163
+ Default: ` [] `
164
+
165
+ ### ☑️ ` url-segment `
166
+
167
+ The index of the URL segment that has the locale, when using the ` UrlDetector ` .
168
+
169
+ Default: ` 1 `
170
+
171
+ ### ☑️ ` route-action `
172
+
173
+ The custom route action that holds the locale, when using the ` RouteActionDetector ` .
174
+
175
+ Default: ` locale `
176
+
177
+ To use the custom route action ` locale ` , you register a route like this:
178
+
179
+ ``` php
180
+ Route::group(['locale' => 'nl'], function () {
181
+ //Route::get(...);
182
+ });
183
+ ```
184
+
185
+ ### ☑️ ` user-attribute `
186
+
187
+ The attribute on the user model that holds the locale, when using the ` UserDetector ` .
188
+ If the user model does not have this attribute, this detector check will be skipped.
189
+
190
+ Default: ` locale `
191
+
192
+ ### ☑️ ` session-key `
193
+
194
+ The session key that holds the locale, when using the ` SessionDetector ` and ` SessionStore ` .
195
+
196
+ Default: ` locale `
197
+
198
+ ### ☑️ ` cookie-name `
199
+
200
+ The name of the cookie that holds the locale, when using the ` CookieDetector ` and ` CookieStore ` .
201
+
202
+ Default: ` locale `
203
+
204
+ ### ☑️ ` cookie-minutes `
205
+
206
+ The lifetime of the cookie that holds the locale, when using the ` CookieStore ` .
207
+
208
+ Default: ` 60 * 24 * 365 ` (1 year)
209
+
210
+ ## 🚧 Testing
144
211
145
212
``` bash
146
213
composer test
147
214
```
215
+ ## ☕️ Credits
216
+
217
+ - [ Ivan Vermeyen] ( https://github.com/ivanvermeyen )
218
+ - [ All contributors] ( https://github.com/codezero-be/laravel-localizer/contributors )
148
219
149
- ## Security
220
+ ## 🔒 Security
150
221
151
222
If you discover any security related issues, please
[ e-mail me
] ( mailto:[email protected] ) instead of using the issue tracker.
152
223
153
- ## Changelog
224
+ ## 📑 Changelog
154
225
155
226
A complete list of all notable changes to this package can be found on the
156
227
[ releases page] ( https://github.com/codezero-be/laravel-localizer/releases ) .
157
228
158
- ## License
229
+ ## 📜 License
159
230
160
231
The MIT License (MIT). Please see [ License File] ( LICENSE.md ) for more information.
0 commit comments