Skip to content

Simple and stupid package for set locale from user data, http header, post data etc.

License

Notifications You must be signed in to change notification settings

trin4ik/laravel-middleware-setlocale

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Laravel Middleware SetLocale

Latest Version on Packagist Total Downloads

Simple and stupid package for set locale from user data, http header, post data etc.

Installation

composer require trin4ik/laravel-middleware-setlocale
php artisan vendor:publish --provider "Trin4ik\LaravelMiddlewareSetLocale\MiddlewareSetLocaleServiceProvider"

And add middleware to app/Http/Kernel.php to needs routes middleware, or to global:

<?php
namespace App\Http;
...

class Kernel extends HttpKernel
{
    protected $middleware = [
        ...
        
        \Trin4ik\LaravelMiddlewareSetLocale\Http\Middleware\SetLocale::class
    ];

Usage

in .env or config/setlocale.php u can configure locale sniffer:

Key Default Description
SET_LOCALE_DEFAULT en Default locale
SET_LOCALE_METHODS get,header U have 4 methods to sniff locale, from user data, from get or post fields or from custom header. The last method gets the highest priority
SET_LOCALE_METHOD_USER locale User attribute, where sets locale data. Like User::find(1)->locale
SET_LOCALE_METHOD_HEADER x-locale Custom http header, like HTTP_X_LOCALE
SET_LOCALE_METHOD_GET locale Get param like /?locale=fr
SET_LOCALE_METHOD_POST locale Post field like $request->post('locale')
SET_LOCALE_ALLOW en,ru Allowed locales. others set the default

Changelog

Please see CHANGELOG for more information what has changed recently.

Security

If you discover any security related issues, please email [email protected] instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.

About

Simple and stupid package for set locale from user data, http header, post data etc.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages