Skip to content

Commit

Permalink
Enhanced L10N detection
Browse files Browse the repository at this point in the history
- Swithced priority between Laravel conf value and browser accepted languages
- normalized L10N to ISO 639-1 format
  • Loading branch information
dharmann committed Jan 11, 2025
1 parent 8f91b80 commit b3b8289
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/LanguageSwitch.php
Original file line number Diff line number Diff line change
Expand Up @@ -273,10 +273,12 @@ public function getPreferredLocale(): string
request()->get('locale') ??
request()->cookie('filament_language_switch_locale') ??
$this->getUserPreferredLocale() ??
config('app.locale', 'en') ??
request()->getPreferredLanguage();

return in_array($locale, $this->getLocales(), true) ? $locale : config('app.locale');
// Usually browsers return the locale in the format of `en-US`, but we only need the first part.
$locale = substr($locale, 0, 2);

return in_array($locale, $this->getLocales(), true) ? $locale : config('app.locale', 'en');
}

public function getMaxHeight(): string
Expand Down

0 comments on commit b3b8289

Please sign in to comment.