From 98bcb8c939e23c7f86f891d2f005c0120a417bfb Mon Sep 17 00:00:00 2001 From: TL Date: Tue, 2 Aug 2022 19:39:22 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AF=AD=E8=A8=80=E5=88=87=E6=8D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Http/Kernel.php | 1 + app/Http/Middleware/Language.php | 20 +++++++++++-------- .../Lang/{zh-CN => zh_cn}/header.php | 0 resources/lang/{zh-CN => zh_cn}/auth.php | 0 resources/lang/{zh-CN => zh_cn}/currency.php | 0 resources/lang/{zh-CN => zh_cn}/order.php | 0 .../lang/{zh-CN => zh_cn}/pagination.php | 0 resources/lang/{zh-CN => zh_cn}/passwords.php | 0 .../lang/{zh-CN => zh_cn}/validation.php | 0 9 files changed, 13 insertions(+), 8 deletions(-) rename plugins/HeaderMenu/Lang/{zh-CN => zh_cn}/header.php (100%) rename resources/lang/{zh-CN => zh_cn}/auth.php (100%) rename resources/lang/{zh-CN => zh_cn}/currency.php (100%) rename resources/lang/{zh-CN => zh_cn}/order.php (100%) rename resources/lang/{zh-CN => zh_cn}/pagination.php (100%) rename resources/lang/{zh-CN => zh_cn}/passwords.php (100%) rename resources/lang/{zh-CN => zh_cn}/validation.php (100%) diff --git a/app/Http/Kernel.php b/app/Http/Kernel.php index 66a78d7e..a6828ca3 100644 --- a/app/Http/Kernel.php +++ b/app/Http/Kernel.php @@ -33,6 +33,7 @@ class Kernel extends HttpKernel \Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class, \Illuminate\Session\Middleware\StartSession::class, // \Illuminate\Session\Middleware\AuthenticateSession::class, + \App\Http\Middleware\Language::class, \Illuminate\View\Middleware\ShareErrorsFromSession::class, \App\Http\Middleware\VerifyCsrfToken::class, \Illuminate\Routing\Middleware\SubstituteBindings::class, diff --git a/app/Http/Middleware/Language.php b/app/Http/Middleware/Language.php index 64c8dd49..a5261c05 100644 --- a/app/Http/Middleware/Language.php +++ b/app/Http/Middleware/Language.php @@ -2,26 +2,30 @@ namespace App\Http\Middleware; -use Beike\Repositories\LanguageRepo; use Closure; +use Illuminate\Http\RedirectResponse; use Illuminate\Http\Request; +use Illuminate\Http\Response; use Illuminate\Support\Facades\App; +use Psr\Container\ContainerExceptionInterface; +use Psr\Container\NotFoundExceptionInterface; class Language { /** * Handle an incoming request. * - * @param \Illuminate\Http\Request $request - * @param \Closure(\Illuminate\Http\Request): (\Illuminate\Http\Response|\Illuminate\Http\RedirectResponse) $next - * @return \Illuminate\Http\Response|\Illuminate\Http\RedirectResponse + * @param Request $request + * @param Closure(\Illuminate\Http\Request): (\Illuminate\Http\Response|\Illuminate\Http\RedirectResponse) $next + * @return Response|RedirectResponse + * @throws ContainerExceptionInterface + * @throws NotFoundExceptionInterface */ public function handle(Request $request, Closure $next) { - if (Session()->has('locale') AND array_key_exists(Session()->get('locale'), languages())) { - App::setLocale(Session()->get('locale')); - } - else { // This is optional as Laravel will automatically set the fallback language if there is none specified + if (session()->has('locale') AND in_array(session()->get('locale'), languages()->toArray())) { + App::setLocale(session()->get('locale')); + } else { // This is optional as Laravel will automatically set the fallback language if there is none specified App::setLocale(system_setting('base.locale')); } return $next($request); diff --git a/plugins/HeaderMenu/Lang/zh-CN/header.php b/plugins/HeaderMenu/Lang/zh_cn/header.php similarity index 100% rename from plugins/HeaderMenu/Lang/zh-CN/header.php rename to plugins/HeaderMenu/Lang/zh_cn/header.php diff --git a/resources/lang/zh-CN/auth.php b/resources/lang/zh_cn/auth.php similarity index 100% rename from resources/lang/zh-CN/auth.php rename to resources/lang/zh_cn/auth.php diff --git a/resources/lang/zh-CN/currency.php b/resources/lang/zh_cn/currency.php similarity index 100% rename from resources/lang/zh-CN/currency.php rename to resources/lang/zh_cn/currency.php diff --git a/resources/lang/zh-CN/order.php b/resources/lang/zh_cn/order.php similarity index 100% rename from resources/lang/zh-CN/order.php rename to resources/lang/zh_cn/order.php diff --git a/resources/lang/zh-CN/pagination.php b/resources/lang/zh_cn/pagination.php similarity index 100% rename from resources/lang/zh-CN/pagination.php rename to resources/lang/zh_cn/pagination.php diff --git a/resources/lang/zh-CN/passwords.php b/resources/lang/zh_cn/passwords.php similarity index 100% rename from resources/lang/zh-CN/passwords.php rename to resources/lang/zh_cn/passwords.php diff --git a/resources/lang/zh-CN/validation.php b/resources/lang/zh_cn/validation.php similarity index 100% rename from resources/lang/zh-CN/validation.php rename to resources/lang/zh_cn/validation.php