misc_pterodactyl-panel/app/Http/Middleware/LanguageMiddleware.php

36 lines
696 B
PHP
Raw Permalink Normal View History

2016-01-21 03:39:02 +00:00
<?php
2016-12-07 22:46:38 +00:00
2016-01-21 03:39:02 +00:00
namespace Pterodactyl\Http\Middleware;
use Closure;
2017-10-29 17:37:25 +00:00
use Illuminate\Http\Request;
2017-11-03 23:16:49 +00:00
use Illuminate\Foundation\Application;
2016-01-21 03:39:02 +00:00
class LanguageMiddleware
{
2017-11-03 23:16:49 +00:00
/**
* @var \Illuminate\Foundation\Application
*/
private $app;
2017-10-29 17:37:25 +00:00
/**
* LanguageMiddleware constructor.
*/
2018-09-03 22:17:53 +00:00
public function __construct(Application $app)
2017-10-29 17:37:25 +00:00
{
2017-11-03 23:16:49 +00:00
$this->app = $app;
2017-10-29 17:37:25 +00:00
}
2016-01-21 03:39:02 +00:00
/**
2018-09-03 22:17:53 +00:00
* Handle an incoming request and set the user's preferred language.
2016-01-21 03:39:02 +00:00
*
* @return mixed
*/
2017-10-29 17:37:25 +00:00
public function handle(Request $request, Closure $next)
2016-01-21 03:39:02 +00:00
{
2018-09-03 22:17:53 +00:00
$this->app->setLocale($request->user()->language ?? config('app.locale', 'en'));
2016-12-07 22:46:38 +00:00
2016-01-21 03:39:02 +00:00
return $next($request);
}
}