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:
A starting point for testing filamentPHP with tenant aware resources.
when you have a lot of resources, let your users search for what they looking for int he sidebar.
get translatable attribute in a relationships
set any page like List Or view page as the main page instead of using a dashboard page in filamentPHP