order navigation group with multi languages

Filament::registerNavigationGroups([
__('messages.services'),
__('messages.abouts'),
__('messages.blogs'),
__('Offers'),
__('messages.bookings'),
__('Pages'),
__('Settings'),
]);
Filament::registerNavigationGroups([
__('messages.services'),
__('messages.abouts'),
__('messages.blogs'),
__('Offers'),
__('messages.bookings'),
__('Pages'),
__('Settings'),
]);
it works with English only do I have to add them in each language?
15 Replies
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
Mohamed Melouk
Mohamed MeloukOP2y ago
Thanks, but I'm using it inside Filament::serving() but I'm using custom service provider FilamentServiceProvider and I registered it in config/app.php and it already working on English language, but not on others. I'll try to move it in AppServiceProvider and see I moved it in appServiceProvider and still works on English only
Mohamed Melouk
Mohamed MeloukOP2y ago
here is the position on English (look at cart icon) and after changing language it changes to the default order
Mohamed Melouk
Mohamed MeloukOP2y ago
Here is my boot method
public function boot(): void
{
Filament::serving(function () {
Filament::registerNavigationGroups([
__('messages.services'),
__('messages.abouts'),
__('messages.blogs'),
__('Offers'),
__('messages.bookings'),
__('Pages'),
__('Settings'),
]);
});
}
public function boot(): void
{
Filament::serving(function () {
Filament::registerNavigationGroups([
__('messages.services'),
__('messages.abouts'),
__('messages.blogs'),
__('Offers'),
__('messages.bookings'),
__('Pages'),
__('Settings'),
]);
});
}
Dan Harrin
Dan Harrin2y ago
so for this case i would reccomend a different approach navigation items should have an english group name as an “id” for that group and then in the service provider, you can map the IDs to translated labels when you register the nav groups… ‘offers’ => NavigationGroup::make()->label(__(‘Offers’))
Mohamed Melouk
Mohamed MeloukOP2y ago
thanks Dan, this is a better approach and works fine sorry Dan, I didn't notice that translation doesn't work by that approach.
Filament::serving(function () {
Filament::registerNavigationGroups([
'services' => NavigationGroup::make()
>label(__('messages.services')),
'abouts' => NavigationGroup::make()
->label(__('messages.abouts')),

'blogs' => NavigationGroup::make()
->label(__('messages.blogs')),
'offers' => NavigationGroup::make()
->label(__('Offers')),
'booking' => NavigationGroup::make()
->label(__('messages.booking')),
'pages' => NavigationGroup::make()
->label(__('Pages')),
'settings' => NavigationGroup::make()
->label(__('Settings')),
]);
});
Filament::serving(function () {
Filament::registerNavigationGroups([
'services' => NavigationGroup::make()
>label(__('messages.services')),
'abouts' => NavigationGroup::make()
->label(__('messages.abouts')),

'blogs' => NavigationGroup::make()
->label(__('messages.blogs')),
'offers' => NavigationGroup::make()
->label(__('Offers')),
'booking' => NavigationGroup::make()
->label(__('messages.booking')),
'pages' => NavigationGroup::make()
->label(__('Pages')),
'settings' => NavigationGroup::make()
->label(__('Settings')),
]);
});
am I missing something?
Dan Harrin
Dan Harrin2y ago
wdym by translation doesnt work?
Mohamed Melouk
Mohamed MeloukOP2y ago
the navigation group show like that messages.abouts sorry I mean it's always in english
Mohamed Melouk
Mohamed MeloukOP2y ago
Mohamed Melouk
Mohamed MeloukOP2y ago
@Dan Harrin sorry for that
Dan Harrin
Dan Harrin2y ago
where are you setting the locale
Mohamed Melouk
Mohamed MeloukOP2y ago
Filament
Language Switch by Bezhan Salleh - Plugins - Filament
Zero config Language Switch(Changer/Localizer) plugin for Filamentphp Admin
Mohamed Melouk
Mohamed MeloukOP2y ago
app()->getLocale() returns the right language, ar for arabic and en for english oh app()->getLocale() inside the boot method return en all the time I'm using filament languages switcher plugin
Dan Harrin
Dan Harrin2y ago
try adding BezhanSalleh\FilamentLanguageSwitch\Http\Middleware\SwitchLanguageLocale to the middleware array in config make sure it goes before the DispatchServingFilamentEvent
Mohamed Melouk
Mohamed MeloukOP2y ago
that works, thank you

Did you find this page helpful?