Skip to content
Discussion options

You must be logged in to vote

In the past (Laravel 8) I have added a Localization middleware in the Kernel.php - in the web $middlewareGroups.

The middleware itself is pretty simple (I am writing just a simple piece of it):

class Localization
{
    public function handle(Request $request, Closure $next)
    {
        $locale = Auth::user()?->locale ?? 'en';
        App::setLocale($locale);

        return $next($request);
    }
}

Then you can decide how/when the user can change the locale.

Of course, if you prefer, you could also store the locale in the current session and preset it from there.

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
1 reply
@blondie63
Comment options

Comment options

You must be logged in to vote
0 replies
Answer selected by jcastroa87
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants