11# Laravel Localizer
22
33[ ![ GitHub release] ( https://img.shields.io/github/release/codezero-be/laravel-localizer.svg?style=flat-square )] ( https://github.com/codezero-be/laravel-localizer/releases )
4- [ ![ Laravel] ( https://img.shields.io/badge/laravel-10 -red?style=flat-square&logo=laravel&logoColor=white )] ( https://laravel.com )
4+ [ ![ Laravel] ( https://img.shields.io/badge/laravel-11 -red?style=flat-square&logo=laravel&logoColor=white )] ( https://laravel.com )
55[ ![ License] ( https://img.shields.io/packagist/l/codezero/laravel-localizer.svg?style=flat-square )] ( LICENSE.md )
66[ ![ Build Status] ( https://img.shields.io/github/actions/workflow/status/codezero-be/laravel-localizer/run-tests.yml?style=flat-square&logo=github&logoColor=white&label=tests )] ( https://github.com/codezero-be/laravel-localizer/actions )
77[ ![ Code Coverage] ( https://img.shields.io/codacy/coverage/ad6fcea152b449d380a187a375d0f7d7/master?style=flat-square )] ( https://app.codacy.com/gh/codezero-be/laravel-localizer )
@@ -19,8 +19,8 @@ Automatically detect and set an app locale that matches your visitor's preferenc
1919
2020## ✅ Requirements
2121
22- - PHP >= 7.2.5
23- - Laravel >= 7 .0
22+ - PHP >= 8.1
23+ - Laravel >= 10 .0
2424
2525## ⬆ Upgrade
2626
@@ -39,13 +39,36 @@ Laravel will automatically register the ServiceProvider.
3939
4040## 🧩 Add Middleware
4141
42- Add the middleware to the ` web ` middleware group in ` app/Http/Kernel.php ` .
42+ By default, the app locale will always be what you configured in ` config/app.php ` .
43+ To automatically update the app locale, you need to register the middleware in the ` web ` middleware group.
4344Make sure to add it after ` StartSession ` and before ` SubstituteBindings ` .
4445
4546The order of the middleware is important if you are using localized route keys (translated slugs)!
4647The session needs to be active when setting the locale, and the locale needs to be set when substituting the route bindings.
4748
49+ ### Laravel 11 and newer:
50+
51+ Add the middleware to the ` web ` middleware group in ` bootstrap/app.php ` .
52+
53+ ``` php
54+ // bootstrap/app.php
55+ ->withMiddleware(function (Middleware $middleware) {
56+ $middleware->web(remove: [
57+ \Illuminate\Routing\Middleware\SubstituteBindings::class,
58+ ]);
59+ $middleware->web(append: [
60+ \CodeZero\Localizer\Middleware\SetLocale::class,
61+ \Illuminate\Routing\Middleware\SubstituteBindings::class,
62+ ]);
63+ })
64+ ```
65+
66+ ### Laravel 10:
67+
68+ Add the middleware to the ` web ` middleware group in ` app/Http/Kernel.php ` .
69+
4870``` php
71+ // app/Http/Kernel.php
4972protected $middlewareGroups = [
5073 'web' => [
5174 //...
0 commit comments