F
Filament3mo ago
Aman

How can use Select with translation by lang file on select Options

How can use Select with translation by lang file on select Options use Translatable; use Filament\Resources\Concerns\Translatable; Select::make('option') ->options(fn () => [ 'monthly' => __('content.priceing.monthly_label'), 'one-time' => __('content.priceing.one_time_label'), ]) ->live() ->nullable()->columnSpan(6) https://prnt.sc/fx6ctwHPv505
Lightshot
Screenshot
Captured with Lightshot
2 Replies
Lara Zeus
Lara Zeus3mo ago
when using __() it will only read the app locale you may do something like:
->options(fn(Component $livewire) => [
'monthly' => __('content.priceing.monthly_label_' . $livewire->activeLocale),
'one-time' => __('content.priceing.one_time_label_' . $livewire->activeLocale),
])
->options(fn(Component $livewire) => [
'monthly' => __('content.priceing.monthly_label_' . $livewire->activeLocale),
'one-time' => __('content.priceing.one_time_label_' . $livewire->activeLocale),
])
Martin Oscar
Martin Oscar3mo ago
Hey the definition is
function __($key = null, $replace = [], $locale = null)
{
if (is_null($key)) {
return $key;
}

return trans($key, $replace, $locale);
}
function __($key = null, $replace = [], $locale = null)
{
if (is_null($key)) {
return $key;
}

return trans($key, $replace, $locale);
}
So you should be able to use
->options(fn(Component $livewire) => [
'monthly' => __('content.priceing.monthly_label', locale: $livewire->activeLocale),
'one-time' => __('content.priceing.one_time_label', locale: $livewire->activeLocale)
])
->options(fn(Component $livewire) => [
'monthly' => __('content.priceing.monthly_label', locale: $livewire->activeLocale),
'one-time' => __('content.priceing.one_time_label', locale: $livewire->activeLocale)
])

Did you find this page helpful?