Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom user menu item not being translated #2683

Closed
cawecoy opened this issue Jun 20, 2024 · 1 comment
Closed

Custom user menu item not being translated #2683

cawecoy opened this issue Jun 20, 2024 · 1 comment

Comments

@cawecoy
Copy link

cawecoy commented Jun 20, 2024

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
Copy link
Author

cawecoy commented Jun 20, 2024

Sorry, I opened this issue on the wrong repository

@cawecoy cawecoy closed this as completed Jun 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant