calamandrei-lorenzo/laravel-browser-lang

Auto detect browser language with middleware.

1.0.1 2020-08-24 08:35 UTC

This package is auto-updated.

Last update: 2024-10-24 18:11:22 UTC


README

Auto detect browser default language

Build Status Latest Stable Version Latest Unstable Version Scrutinizer Code Quality Code Coverage Total Downloads License

This package make available a middleware that auto-detect the language accepted from the browser and set it as current locale.

Requirement

  1. PHP >= 7.4
  2. 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:

  1. File bug reports using the issue tracker.
  2. Answer questions or fix bugs on the issue tracker.
  3. 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