F
Filament16mo ago
gizmojo

How to read the lang file/translation when registering navigationItems in a panel?

E.g this displays the 'filament-panels::layout.actions.billing.label' instead of the translated label.
public function panel(Panel $panel): Panel
{
return $panel
// ...
->navigationItems([
NavigationItem::make('billing')
->label(__('filament-panels::layout.actions.billing.label'))
]);
}
public function panel(Panel $panel): Panel
{
return $panel
// ...
->navigationItems([
NavigationItem::make('billing')
->label(__('filament-panels::layout.actions.billing.label'))
]);
}
Another issue when registering a custom navigation you've unable to use the resource getUrl method. This used to work in v2 but getting an error that the panel has not been setup yet.
Call to a member function getId() on null
public static function getRouteBaseName(?string $panel = null): string
{
$panel ??= Filament::getCurrentPanel()->getId();
public static function getRouteBaseName(?string $panel = null): string
{
$panel ??= Filament::getCurrentPanel()->getId();
NavigationItem::make('product-redirects')
->url(ProductResource::getUrl('redirects'))
->isActiveWhen(fn () => request()->routeIs(ProductResource::getRouteBaseName() . '.redirects'))
NavigationItem::make('product-redirects')
->url(ProductResource::getUrl('redirects'))
->isActiveWhen(fn () => request()->routeIs(ProductResource::getRouteBaseName() . '.redirects'))
Redirects is a custom list resource page which needs registering manually
public static function getPages(): array
{
return [
'index' => Pages\ListProductRedirect::route('/'),
'redirects' => Pages\ListProductRedirect::route('/redirects'),
];
}
public static function getPages(): array
{
return [
'index' => Pages\ListProductRedirect::route('/'),
'redirects' => Pages\ListProductRedirect::route('/redirects'),
];
}
Tried to manually use route() helper function instead of the getting the resources but that does not work either.
Route [filament.admin.resources.products.index] not defined.
->navigationItems([
NavigationItem::make()
->label('Settings')
->url(route('filament.admin.resources.products.index'))
->icon('heroicon-o-cog-6-tooth'),
])
->navigationItems([
NavigationItem::make()
->label('Settings')
->url(route('filament.admin.resources.products.index'))
->icon('heroicon-o-cog-6-tooth'),
])
Confirmed the route name is correct and visible when I run php artisan route:list. Adding debug code to test the routes collection is empty at the point of registering the panel configuration dd(Route::getRoutes());
Solution:
Got it working in the end cheers for the help guys! I found that I needed to update all calls to the label/group language calls otherwise it broke them all. Took a lot of trial and error with loads of coffee...
Jump to solution
5 Replies
Patrick Boivin
Patrick Boivin16mo ago
Have you tried a closure for the label? e.g. ->label(fn () => __('filament-panels::layout.actions.billing.label'))
awcodes
awcodes16mo ago
If it’s showing the translation key that means there is no key set it the translations for it. For the null current panel, make sure you have at least one of your panels set with ->default() especially if you only have one panel.
gizmojo
gizmojoOP16mo ago
Cheers guys using a closer for the URL has fixed that issue. But still getting the label issue even when inside a closer. It works fine when everything is cached - only an issue when clearing the cache:
php artisan optimize:clear
php artisan optimize:clear
Testing futher - Works fine in a standalone project loading the local language file. - It's only issue when loading language from other the current package or another package
// awcodes/filament-table-repeater - WORKS
->label(fn () => __('filament-table-repeater::components.repeater.row_actions.label'))

// filament/filament - WORKS now in closure
->label(fn () => __('filament-panels::layout.actions.billing.label'))

// custom/package - BROKEN
->label(fn () => __('custom::package.label'))

// ryangjchandler/navigation - BROKEN
->label(fn () => __('filament-navigation::filament-navigation.items.empty'))
// awcodes/filament-table-repeater - WORKS
->label(fn () => __('filament-table-repeater::components.repeater.row_actions.label'))

// filament/filament - WORKS now in closure
->label(fn () => __('filament-panels::layout.actions.billing.label'))

// custom/package - BROKEN
->label(fn () => __('custom::package.label'))

// ryangjchandler/navigation - BROKEN
->label(fn () => __('filament-navigation::filament-navigation.items.empty'))
My package name beings with a 'c' so it looks to be a problem loading the language file of that package and any below that alphabetically.
Solution
gizmojo
gizmojo16mo ago
Got it working in the end cheers for the help guys! I found that I needed to update all calls to the label/group language calls otherwise it broke them all. Took a lot of trial and error with loads of coffee
Vitor Corrêa
Vitor Corrêa14mo ago
Hey guys. I have the following error when clicking the button to impersonate Call to undefined method Filament\FilamentManager::getCurrentPanel() Has anyone ever get this problem?
No description
Want results from more Discord servers?
Add your server