Skip to content

Commit

Permalink
done
Browse files Browse the repository at this point in the history
  • Loading branch information
bezhanSalleh committed Jan 9, 2024
1 parent b6defe3 commit 2aa1b35
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 18 deletions.
16 changes: 3 additions & 13 deletions src/Events/LocaleChanged.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
){
}
}
14 changes: 9 additions & 5 deletions src/Http/Middleware/SwitchLanguageLocale.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();

$userLocales = preg_split('/[,;]/', $request->server('HTTP_ACCEPT_LANGUAGE'));

foreach ($userLangs as $locale) {
return in_array($locale, LanguageSwitch::make()->getLocales())
? $locale
: null;
foreach ($userLocales as $locale) {
if (in_array($locale, $appLocales)) {
return $locale;
}
}

return null;
}
}

0 comments on commit 2aa1b35

Please sign in to comment.