spatie / laravel-permission

Associate users with roles and permissions
https://spatie.be/docs/laravel-permission
MIT License
11.96k stars 1.75k forks source link

Custom user menu item not being translated #2683

Closed cawecoy closed 3 weeks ago

cawecoy commented 3 weeks ago

Description

Custom user menu item is not being translated, it is always shown in the app's main language, no matter the user switches to another language.

Steps To Reproduce

I am using filament/spatie-laravel-translatable-plugin.

Provider:

use App\Filament\Pages\Settings;
use Filament\Navigation\MenuItem;
use Filament\Panel;
use Filament\SpatieLaravelTranslatablePlugin;

public function panel(Panel $panel): Panel
{
    return $panel
        // ...
        ->userMenuItems([
            MenuItem::make()
                ->label(__('admin.settings'))
                ->url('#')
                ->icon('heroicon-o-cog-6-tooth'),
            // ...
        ])
        ->plugins([
                SpatieLaravelTranslatablePlugin::make()
                    ->defaultLocales(['en', 'es']),
        ]);
}

lang/en/admin.php:

return ['settings' => 'Settings'];

lang/es/admin.php:

return ['settings' => 'Ajustes'];

Note that the offical doc shows something like ->label('Settings') but I am doing ->label(__('admin.settings')) because my app's user menu should be translatable.

But when the user switches the language to Spanish, it still shows "Settings" (custom user menu items are the only things in my application that are not translated to Spanish, it is still in English language). The Filament native built-in "Logout" user menu item is translated correctly, it's only my CUSTOM menu items that are not being translated at all.

Additional information: I've found a workaround to make it work using closure.

->label(fn (): string => __('admin.settings'))

But I expect it to work using just ->label(__('admin.settings')) without the workaround.

Example Application

No response

Version of spatie/laravel-permission package:

6.7.0

Version of laravel/framework package:

v10.48.12

PHP version:

8.2.18

Database engine and version:

No response

OS: Windows/Mac/Linux version:

No response

cawecoy commented 3 weeks ago

Sorry, I opened this issue on the wrong repository