From a2e70dd6b2509476b68ff0d518f33bb05f7de37e Mon Sep 17 00:00:00 2001 From: Brady Wetherington Date: Fri, 8 Mar 2024 14:04:21 +0000 Subject: [PATCH] Fix [sc-25008] - correct and improve legacy language warnings The legacy language warning was misfiring when a user's language didn't match the APP_LOCALE from .env. Additionally, we weren't properly warning when the legacy-language came from Settings or from the user themselves. Both of which should be impossible but still probably not a bad idea to warn on it, anyways --- app/Http/Middleware/CheckLocale.php | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/app/Http/Middleware/CheckLocale.php b/app/Http/Middleware/CheckLocale.php index 3c525d172..d0dbcffaa 100644 --- a/app/Http/Middleware/CheckLocale.php +++ b/app/Http/Middleware/CheckLocale.php @@ -8,6 +8,12 @@ use \App\Helpers\Helper; class CheckLocale { + private function warn_legacy_locale($language, $source) + { + if ($language != Helper::mapLegacyLocale($language)) { + \Log::warning("$source $language and should be updated to be ".Helper::mapLegacyLocale($language)); + } + } /** * Handle the locale for the user, default to settings otherwise. * @@ -22,24 +28,23 @@ class CheckLocale // Default app settings from config $language = config('app.locale'); + $this->warn_legacy_locale($language, "APP_LOCALE in .env is set to"); if ($settings = Setting::getSettings()) { // User's preference if (($request->user()) && ($request->user()->locale)) { $language = $request->user()->locale; + $this->warn_legacy_locale($language, "username ".$request->user()->username." (".$request->user()->id.") has a language"); // App setting preference } elseif ($settings->locale != '') { $language = $settings->locale; + $this->warn_legacy_locale($language, "App Settings is set to"); } } - - if (config('app.locale') != Helper::mapLegacyLocale($language)) { - \Log::warning('Your current APP_LOCALE in your .env is set to "'.config('app.locale').'" and should be updated to be "'.Helper::mapLegacyLocale($language).'" in '.base_path().'/.env. Translations may display unexpectedly until this is updated.'); - } - + \App::setLocale(Helper::mapLegacyLocale($language)); return $next($request); }