mirror of
https://github.com/bs-community/blessing-skin-server.git
synced 2024-12-21 06:19:38 +08:00
Fix switching i18n
This commit is contained in:
parent
6918a46ae8
commit
262d48e1f7
@ -27,7 +27,7 @@ class Kernel extends HttpKernel
|
||||
*/
|
||||
protected $middlewareGroups = [
|
||||
'web' => [
|
||||
\Illuminate\Cookie\Middleware\EncryptCookies::class,
|
||||
\App\Http\Middleware\EncryptCookies::class,
|
||||
\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
|
||||
\Illuminate\Session\Middleware\StartSession::class,
|
||||
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Cookie;
|
||||
use Illuminate\Support\Arr;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Response;
|
||||
@ -10,13 +11,12 @@ class DetectLanguagePrefer
|
||||
{
|
||||
public function handle($request, \Closure $next)
|
||||
{
|
||||
$locale = $request->input('lang') ?? session('locale') ?? $request->getPreferredLanguage();
|
||||
$locale = $request->input('lang') ?? $request->cookie('locale') ?? $request->getPreferredLanguage();
|
||||
if (($info = Arr::get(config('locales'), $locale)) && ($alias = Arr::get($info, 'alias'))) {
|
||||
$locale = $alias;
|
||||
}
|
||||
app()->setLocale($locale);
|
||||
session(['locale' => $locale]);
|
||||
|
||||
Cookie::queue('locale', $locale);
|
||||
return $next($request);
|
||||
}
|
||||
}
|
||||
|
17
app/Http/Middleware/EncryptCookies.php
Normal file
17
app/Http/Middleware/EncryptCookies.php
Normal file
@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Illuminate\Cookie\Middleware\EncryptCookies as Middleware;
|
||||
|
||||
class EncryptCookies extends Middleware
|
||||
{
|
||||
/**
|
||||
* The names of the cookies that should not be encrypted.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $except = [
|
||||
'locale',
|
||||
];
|
||||
}
|
Loading…
Reference in New Issue
Block a user