craft-forge/filament-language-switcher
Composer 安装命令:
composer require 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.
README 文档
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. Supports auth pages, cookie persistence, and locale change events.
Demo
Installation
| Plugin Version | Filament Version | PHP Version |
|---|---|---|
| 1.x | 3.x, 4.x, 5.x | > 8.1 |
1. Install the package via Composer:
composer require craft-forge/filament-language-switcher
2. Register the plugin in your Filament panel configuration (e.g. AdminPanelProvider):
use CraftForge\FilamentLanguageSwitcher\FilamentLanguageSwitcherPlugin; 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
Locales
By default, the plugin auto-detects available Filament language files. To define the locale list manually, pass it to locales() - choose one of three formats:
Locale codes - names and flags are resolved automatically from the built-in dictionary (200+ languages):
FilamentLanguageSwitcherPlugin::make() ->locales(['en', 'fr', 'de'])
Full control - specify name and flag per locale. Flag codes reference: https://flagicons.lipis.dev.
FilamentLanguageSwitcherPlugin::make() ->locales([ ['code' => 'en', 'name' => 'English', 'flag' => 'us'], ['code' => 'fr', 'name' => 'Français', 'flag' => 'fr'], ['code' => 'de', 'name' => 'Deutsch', 'flag' => 'de'], ])
Dynamic - load locales at runtime (e.g. from a database):
FilamentLanguageSwitcherPlugin::make() ->locales(fn () => Language::pluck('code')->toArray())
Remember Locale
Store the selected locale in a cookie to persist across browser sessions (e.g. after logout):
FilamentLanguageSwitcherPlugin::make() ->rememberLocale() // forever ->rememberLocale(days: 30) // for 30 days
Custom Render Hook
Change where the language switcher appears in the panel:
use Filament\View\PanelsRenderHook; FilamentLanguageSwitcherPlugin::make() ->renderHook(PanelsRenderHook::USER_MENU_PROFILE_AFTER)
Popular placements:
USER_MENU_BEFORE— before the user menu (default)USER_MENU_PROFILE_AFTER— after user profile in dropdownUSER_MENU_AFTER— after the user menuSIDEBAR_FOOTER— at the bottom of sidebarFOOTER— in the page footer
All available render hooks: https://filamentphp.com/docs/5.x/advanced/render-hooks
Show on Auth Pages
Display the language switcher on login, register, and password reset pages:
FilamentLanguageSwitcherPlugin::make() ->showOnAuthPages()
Hide Flags
Display only language names without flag icons:
FilamentLanguageSwitcherPlugin::make() ->showFlags(false)
Event
The plugin dispatches a LocaleChanged event whenever a user switches locale, providing both the new and previous locale:
use CraftForge\FilamentLanguageSwitcher\Events\LocaleChanged; use Illuminate\Support\Facades\Event; public function boot(): void { Event::listen(LocaleChanged::class, function (LocaleChanged $event) { // auth()->user()->setLocale($event->newLocale); // Log::info("Locale changed from {$event->oldLocale} to {$event->newLocale}"); }); }
License
The MIT License (MIT). Please see License File for more information.
craft-forge/filament-language-switcher 适用场景与选型建议
craft-forge/filament-language-switcher 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 48.64k 次下载、GitHub Stars 达 11, 最近一次更新时间为 2025 年 09 月 12 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「admin」 「i18n」 「language」 「laravel」 「localization」 「switcher」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 craft-forge/filament-language-switcher 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 craft-forge/filament-language-switcher 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 craft-forge/filament-language-switcher 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Texy converts plain text in easy to read Texy syntax into structurally valid (X)HTML. It supports adding of images, links, nested lists, tables and has full support for CSS. Texy supports hyphenation of long words (which reflects language rules), clickable emails and URL (emails are obfuscated again
Easy to use i18n translation PHP class for multi-language websites
Package for convenient work with Laravel's localization features
Store your language lines in the database, yaml or other sources
A custom URL rule class for Yii 2 which allows to create translated URL rules
2lenet/EasyAdminPlusBundle
统计信息
- 总下载量: 48.64k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 12
- 点击次数: 48
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-09-12



