Add a Language Switcher Under The User Menu
- Published: 22 Apr 2024 Updated: 04 May 2024
Integrate Language Switcher in User Menu for a Cleaner Top Bar
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:
Related Tricks:
Let Users to Select All Options with a Simple Hint Action
when you have a lot of resources, let your users search for what they looking for int he sidebar.
how to redirect the user after loging out of filament app
This time-saving starter kit provides a Laravel project with FilamentPHP already installed and configured, so you can dive straight into building without any of the initial setup headaches.
Bring the sticky actions back form filament v2