Auto detect browser default language
This package make available a middleware that auto-detect the language accepted from the browser and set it as current locale.
- PHP >= 7.4
- laravel/framework >= 5.8|6.0|7.0
Tested on laravel/framework >= 7.0
$ composer require calamandrei-lorenzo/laravel-browser-lang
Optional, you can publish the config file:
$ php artisan vendor:publish --provider="CalamandreiLorenzo\\LaravelBrowserLang\\ServiceProvider" --tag=config
Implement the middleware in your App\Http\Kernel
:
use CalamandreiLorenzo\LaravelBrowserLang\Http\Middleware\BrowserLang;
class Kernel extends HttpKernel
{
/**
* The application's route middleware.
*
* These middleware may be assigned to groups or used individually.
*
* @var array
*/
protected $routeMiddleware = [
// ...
'detect-language' => BrowserLang::class
];
}
Route::middleware('detect-language')->group(static function () {
// routes
});
Otherwise set it as a global middleware in your App\Http\Kernel
file.
class Kernel extends HttpKernel
{
/**
* The application's global HTTP middleware stack.
*
* These middleware are run during every request to your application.
*
* @var array
*/
protected $middleware = [
// ...
BrowserLang::class
];
}
You can contribute in one of three ways:
- File bug reports using the issue tracker.
- Answer questions or fix bugs on the issue tracker.
- Contribute new features or update the wiki.
The code contribution process is not very formal. You just need to make sure that you follow the PSR-0, PSR-1, and PSR-2 coding guidelines. Any new code contributions must be accompanied by unit tests where applicable.
MIT