F
Filament6mo ago
Jessy

how to translate the option in a Select?

Forms\Components\Select::make('website_type_id')
->label(__('Type'))
->options(WebsiteType::all()->pluck('name', 'id'))
->required(),
Forms\Components\Select::make('website_type_id')
->label(__('Type'))
->options(WebsiteType::all()->pluck('name', 'id'))
->required(),
I tried : ->options((WebsiteType::all()->pluck( ('name')), 'id')), but doesn't work.
Solution:
You need to ->map() your names to the translated names.
Jump to solution
4 Replies
Dennis Koch
Dennis Koch6mo ago
Where are your translations? In a translation file? Please format your code properly ( #✅┊rules )
Jessy
Jessy6mo ago
in json file, in lang directory I tried also: ->getOptionLabelFromRecordUsing() but works only with relationship(), but I need options()
Solution
Dennis Koch
Dennis Koch6mo ago
You need to ->map() your names to the translated names.
Jessy
Jessy6mo ago
ty