orkhanahmadov / laravel-accept-language-middleware
Laravel middleware for setting application locale based on HTTP Accept-Language header
Fund package maintenance!
orkhanahmadov
Installs: 48 421
Dependents: 1
Suggesters: 0
Security: 0
Stars: 15
Watchers: 2
Forks: 5
Open Issues: 0
Requires
- php: ^8.0.2
- illuminate/contracts: ^8.0|^9.0|^10.0|^11.0
- illuminate/http: ^8.0|^9.0|^10.0|^11.0
- illuminate/support: ^8.0|^9.0|^10.0|^11.0
Requires (Dev)
- orchestra/testbench: ^6.0|^7.0|^8.0|^9.0
- phpunit/phpunit: ^9.0|^10.5
README
Laravel middleware for automatically setting application locale based on HTTP "Accept-Language" header
Requirements
- PHP 8.0 or higher.
- Laravel ^8.0, ^9.0 or higher
Installation
You can install the package via composer:
composer require orkhanahmadov/laravel-accept-language-middleware
Usage
Register \Orkhanahmadov\LaravelAcceptLanguageMiddleware\Middleware::class
middleware in application's HTTP Kernel.
You can install it as global middleware in Kernel's $middleware
property:
protected $middleware = [ ... \Orkhanahmadov\LaravelAcceptLanguageMiddleware\Middleware::class ];
You can install it to specific middleware groups in Kernel's $middlewareGroups
property:
protected $middlewareGroups = [ 'web' => [ ... \Orkhanahmadov\LaravelAcceptLanguageMiddleware\Middleware::class ] ];
Or you can install is as route middleware in Kernel's $routeMiddleware
and use it manually in routes:
Kernel:
protected $routeMiddleware = [ ... 'accept-language' => \Orkhanahmadov\LaravelAcceptLanguageMiddleware\Middleware::class ];
Route file
Route::middleware(['accept-language'])->get('/', 'MyController@index');
Testing
composer test
Changelog
Please see CHANGELOG for more information what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security
If you discover any security related issues, please email ahmadov90@gmail.com instead of using the issue tracker.
Credits
License
The MIT License (MIT). Please see License File for more information.