Home API Tools Posts Hire Me About
Sign In Create Account
Livewire

Building Language Switcher with Livewire v4

February 01, 2026 1 min read 9 views

Build a language switcher.

Component

@php
new class extends Livewire\Component {
    public string $locale;
    
    public function mount(): void
    {
        $this->locale = app()->getLocale();
    }
    
    public function switchLocale(string $locale): void
    {
        session()->put('locale', $locale);
        $this->redirect(request()->header('Referer'));
    }
}
@endphp

@foreach(['en' => 'English', 'ar' => 'العربية'] as $code => $name) @endforeach
Share this post:

Related Posts

Comments (0)

Please log in to leave a comment. Log in

No comments yet. Be the first to comment!