calamandrei-lorenzo / laravel-browser-lang
Auto detect browser language with middleware.
Requires
- php: ^7.4
- laravel/framework: ^6.0|^7.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^2.16
- orchestra/testbench: ^5.3
- phpunit/phpunit: ^8.1|^9.0
- roave/security-advisories: dev-master
This package is auto-updated.
Last update: 2024-10-24 18:11:22 UTC
README
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.
Requirement
- PHP >= 7.4
- laravel/framework >= 5.8|6.0|7.0
Tested on laravel/framework >= 7.0
Installing
$ 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 ]; }
Usage
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 ]; }
Contributing
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.
License
MIT