Search by

eii / filament-language-switch

amit-eiitech

Filament topbar language switcher plugin

Package info

github.com/amit-eiitech/filament-language-switch

pkg:composer/eii/filament-language-switch

Statistics

Installs: 1

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

v1.0.0 2026-11-19 14:01 UTC

This package is auto-updated.

Last update: 2026-11-19 14:09:28 UTC


README

A lightweight locale switcher for Filament panels. It adds a topbar language dropdown, stores the selected locale in the session and a cookie, and applies it to each panel request.

Requirements

  • PHP 8.3 or later
  • Laravel 13
  • Filament 5

Installation

composer require eii/filament-language-switch

Laravel package discovery registers the service provider automatically.

Register the plugin on each Filament panel. Important: Register the plugin after you configure panel middleware in your AdminPanelProvider—panel middleware are applied in the order you chain them, and placing the plugin first can prevent the locale middleware from being attached.

use Eii\FilamentLanguageSwitch\LanguageSwitchPlugin;

public function panel(Panel $panel): Panel
{
    return $panel
        // ...
        ->middleware([
            // your middleware...
        ])
        // IMPORTANT: register the plugin after middleware so SetLocale attaches correctly
        ->plugin(LanguageSwitchPlugin::make());
}

Configuration

Publish the configuration:

php artisan vendor:publish --tag=filament-language-switch-config

Edit config/localization.php to set the default locale and supported locales:

'default' => env('APP_LOCALE', 'en'),

'locales' => [
    'en' => [
        'name' => 'English',
        'native' => 'English',
        'dir' => 'ltr',
        'flag' => '🇺🇸',
    ],
    'es' => [
        'name' => 'Spanish',
        'native' => 'Español',
        'dir' => 'ltr',
        'flag' => '🇪🇸',
    ],
],

The dropdown is hidden when only one locale is configured.

Publishing Views

php artisan vendor:publish --tag=filament-language-switch-views

Published views are stored in resources/views/vendor/filament-language-switch.

Customizing the Render Hook

By default, the switcher is rendered after the global search area. You can choose another Filament render hook:

->plugin(
    LanguageSwitchPlugin::make()
        ->renderHook(\Filament\View\PanelsRenderHook::TOPBAR_END)
)

How Locale Selection Works

The switcher sends the selected locale to GET /locale/{locale}. The package validates it against localization.locales, stores it in the Laravel session, and sets a one-year cookie. The SetLocale middleware applies the session locale, then the cookie locale, and finally the configured default locale.

Add translation files for the application's supported languages in the usual Laravel lang/<locale>/ directories.

Publishing

Before tagging a release:

composer validate --strict
composer dump-autoload --optimize

Test in a Laravel application with Filament 5 and verify plugin registration, route registration, locale switching, RTL direction, and the vendor-published view and config.