mirror of
https://github.com/bs-community/blessing-skin-server.git
synced 2024-12-21 06:19:38 +08:00
3cf19d8656
This pull request applies code style fixes from an analysis carried out by [StyleCI](https://github.styleci.io). --- For more information, click [here](https://github.styleci.io/analyses/8wKwbZ).
37 lines
930 B
PHP
37 lines
930 B
PHP
<?php
|
|
|
|
namespace App\Http\Middleware;
|
|
|
|
use Illuminate\Support\Arr;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Http\Response;
|
|
|
|
class DetectLanguagePrefer
|
|
{
|
|
public function handle($request, \Closure $next)
|
|
{
|
|
$response = $next($request);
|
|
|
|
if ($response instanceof Response) {
|
|
$response->cookie('locale', config('app.locale'));
|
|
}
|
|
|
|
return $response;
|
|
}
|
|
|
|
public function detect(Request $request)
|
|
{
|
|
$locale = $request->input('lang') ?: ($request->cookie('locale') ?: $request->getPreferredLanguage());
|
|
|
|
// If current locale is an alias of other locale
|
|
if (($info = Arr::get(config('locales'), $locale)) && ($alias = Arr::get($info, 'alias'))) {
|
|
$locale = $alias;
|
|
}
|
|
|
|
app()->setLocale($locale);
|
|
AfterSessionBooted::$jobs[] = function () {
|
|
session(['locale' => config('app.locale')]);
|
|
};
|
|
}
|
|
}
|