diff --git a/src/Events/LocaleChanged.php b/src/Events/LocaleChanged.php index 41034cd..e518f30 100644 --- a/src/Events/LocaleChanged.php +++ b/src/Events/LocaleChanged.php @@ -2,20 +2,10 @@ namespace BezhanSalleh\FilamentLanguageSwitch\Events; -use Illuminate\Broadcasting\InteractsWithSockets; -use Illuminate\Foundation\Events\Dispatchable; -use Illuminate\Queue\SerializesModels; - class LocaleChanged { - use Dispatchable; - use InteractsWithSockets; - use SerializesModels; - - /** - * Create a new event instance. - */ - public function __construct(public string $locale) - { + public function __construct( + public string $locale + ) { } } diff --git a/src/Http/Middleware/SwitchLanguageLocale.php b/src/Http/Middleware/SwitchLanguageLocale.php index d20050b..5ea7c08 100644 --- a/src/Http/Middleware/SwitchLanguageLocale.php +++ b/src/Http/Middleware/SwitchLanguageLocale.php @@ -25,12 +25,16 @@ public function handle(Request $request, Closure $next): \Illuminate\Http\Respon private function getBrowserLocale(Request $request): ?string { - $userLangs = preg_split('/[,;]/', $request->server('HTTP_ACCEPT_LANGUAGE')); + $appLocales = LanguageSwitch::make()->getLocales(); - foreach ($userLangs as $locale) { - return in_array($locale, LanguageSwitch::make()->getLocales()) - ? $locale - : null; + $userLocales = preg_split('/[,;]/', $request->server('HTTP_ACCEPT_LANGUAGE')); + + foreach ($userLocales as $locale) { + if (in_array($locale, $appLocales)) { + return $locale; + } } + + return null; } }