logo light

Add a Language Switcher Under The User Menu

Image Description
By: Lara Zeus
  • Published: 22 Apr 2024 Updated: 04 May 2024

Integrate Language Switcher in User Menu for a Cleaner Top Bar

Add a Language Switcher Under The User Menu

Register a Render Hook:

Begin by registering a new render hook to your panel provider. We'll place the switcher in the USER_MENU_PROFILE_AFTER position to keep the top bar clean, but you can register it any position you want.

Use the Dropdown Component

We will use the the dropdown component from Filament to render the sub-navigation for the language switcher. Customize the UI as needed, such as adding flags for different languages.

in your filament.hooks.lang-switcher file:

Implement the Switcher

Create a simple route to capture the selected language and store it in the session:

Set Up a Middleware

Define a middleware to instruct Laravel to pick the locale from the session:

Register the Middleware

Finally, register the middleware within the Filament panel provider:

Back to Tricks