php-monsters / laravel-accept-language-middleware
Laravel middleware for setting application locale based on HTTP Accept-Language header
Fund package maintenance!
samuraee
Requires
- php: ^8.3
- illuminate/contracts: ^12.0
- illuminate/http: ^12.0
- illuminate/support: ^12.0
Requires (Dev)
- orchestra/testbench: ^10.0
- phpunit/phpunit: ^11.0
This package is auto-updated.
Last update: 2025-03-05 16:50:14 UTC
README
Laravel middleware for automatically setting application locale based on HTTP "Accept-Language" header
Requirements
- PHP 8.3 or higher.
- Laravel ^12.0 or higher
Installation
You can install the package via composer:
composer require php-monsters/laravel-accept-language-middleware
Usage
Register \PhpMonsters\LaravelAcceptLanguageMiddleware\Middleware::class
middleware in application's HTTP Kernel.
You can install it as global middleware in Kernel's $middleware
property:
protected $middleware = [ ... \PhpMonsters\LaravelAcceptLanguageMiddleware\Middleware::class ];
You can install it to specific middleware groups in Kernel's $middlewareGroups
property:
protected $middlewareGroups = [ 'web' => [ ... \PhpMonsters\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' => \PhpMonsters\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.
Credits
License
The MIT License (MIT). Please see License File for more information.