amrikasir / lang-selector
Livewire-based language selector for Laravel 11
Installs: 0
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
pkg:composer/amrikasir/lang-selector
Requires
- php: ^8.2
- illuminate/support: ^11.0
- livewire/livewire: ^3.0
This package is auto-updated.
Last update: 2025-10-22 02:39:06 UTC
README
A simple, elegant, and reusable Livewire 3 language switcher for Laravel 11.
This package provides a ready-to-use dropdown component to switch application locales dynamically — complete with middleware, configuration, and publishable views.
✨ Features
- ⚡ Built with Livewire 3
- 🌍 Easy multi-language switching (session-based)
- ⚙️ Configurable via
config/lang-selector.php
- 🎨 Publishable views for full customization
- 🧩 Simple integration with your existing layout
📦 Installation
Require the package via Composer:
composer require amrikasir/lang-selector
⚙️ Publish Config & Views
You can publish the default configuration and views to customize them:
php artisan vendor:publish --tag=lang-selector-config php artisan vendor:publish --tag=lang-selector-views
This will create:
config/lang-selector.php
resources/views/vendor/lang-selector/
🧩 Usage
- Register Middleware
In app/Http/Kernel.php
, add the middleware to your web group:
protected $middlewareGroups = [ 'web' => [ // ... \Kaldiaris\LangSelector\Http\Middleware\LocaleMiddleware::class, ], ];
- Add Component to Blade
Just drop the component anywhere in your layout:
<livewire:language-selector />
That’s it! 🎉
The dropdown will automatically display all available locales from your config.
⚙️ Configuration
config/lang-selector.php
return [ 'available_locales' => [ 'en' => 'English', 'id' => 'Bahasa Indonesia', // add more as needed ], 'default_locale' => 'en', ];
🧠 How It Works
- The
LocaleMiddleware
setsApp::setLocale()
based on the session. - The
LanguageSelector
Livewire component updates session locale dynamically. - The selected locale persists until changed again.
🧰 Example Styling
You can freely modify the published views at:
resources/views/vendor/lang-selector/livewire/language-selector.blade.php
Example minimal Tailwind version:
<div class="relative"> <button wire:click="$toggle('open')" class="px-3 py-2 rounded bg-gray-100 hover:bg-gray-200"> {{ $locales[$current] ?? strtoupper($current) }} </button> @if ($open ?? false) <div class="absolute bg-white border rounded mt-1 shadow"> @foreach ($locales as $key => $label) <button wire:click="setLocale('{{ $key }}')" class="block w-full text-left px-4 py-2 hover:bg-gray-100"> {{ $label }} </button> @endforeach </div> @endif </div>
🧾 License
This package is open-sourced software licensed under the MIT license.