Pterodactyl-Panel/app/Http/Middleware/LanguageMiddleware.php

36 lines
696 B
PHP
Raw Normal View History

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