Pterodactyl-Panel/app/Http/Middleware/LanguageMiddleware.php
2018-09-03 15:17:53 -07:00

40 lines
850 B
PHP

<?php
namespace Pterodactyl\Http\Middleware;
use Closure;
use Illuminate\Http\Request;
use Illuminate\Foundation\Application;
class LanguageMiddleware
{
/**
* @var \Illuminate\Foundation\Application
*/
private $app;
/**
* LanguageMiddleware constructor.
*
* @param \Illuminate\Foundation\Application $app
*/
public function __construct(Application $app)
{
$this->app = $app;
}
/**
* Handle an incoming request and set the user's preferred language.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle(Request $request, Closure $next)
{
$this->app->setLocale($request->user()->language ?? config('app.locale', 'en'));
return $next($request);
}
}