craft-forge / filament-language-switcher
Zero-config language switcher for Filament admin panels. Automatically scans available translations, renders dropdown with country flags, persists selection via sessions.
Requires
- php: ^8.1
- filament/filament: ^3.0|^4.0
- spatie/laravel-package-tools: ^1.16
- stijnvanouplines/blade-country-flags: ^1.0.6
README
A simple and elegant language switcher plugin for Filament admin panels. Automatically detects available Filament translations or allows custom language configuration with optional flag icons.
Installation
Plugin Version | Filament Version | PHP Version |
---|---|---|
1.x | 3.x, 4.x | > 8.1 |
Install the package via Composer:
composer require craft-forge/filament-language-switcher
Usage
Register the plugin in your Filament panel configuration: (e.g. AdminPanelProvider
).
use CraftForge\FilamentLanguageSwitcher\FilamentLanguageSwitcherPlugin; use Filament\Panel; public function panel(Panel $panel): Panel { return $panel // ... ->plugins([ FilamentLanguageSwitcherPlugin::make(), ]); }
The plugin will automatically detect available Filament language files and display them in a dropdown menu.
Configuration
Custom Languages
Define your own language list instead of auto-detection:
FilamentLanguageSwitcherPlugin::make() ->locales([ ['code' => 'en', 'name' => 'English', 'flag' => 'gb'], ['code' => 'uk', 'name' => 'Українська', 'flag' => 'ua'], ['code' => 'de', 'name' => 'Deutsch', 'flag' => 'de'], ])
For flag codes, please refer to https://flagicons.lipis.dev (e.g., pl for Poland).
Hide Flags
Display only language codes and names without flag icons:
FilamentLanguageSwitcherPlugin::make() ->showFlags(false)
Custom Render Hook
Change where the language switcher appears in your panel:
use Filament\View\PanelsRenderHook; FilamentLanguageSwitcherPlugin::make() ->renderHook(PanelsRenderHook::USER_MENU_PROFILE_AFTER)
Available render hooks: https://filamentphp.com/docs/4.x/advanced/render-hooks#panel-builder-render-hooks
License
The MIT License (MIT). Please see License File for more information.