#Spatie Translatable - Checkbox list
32 messages · Page 1 of 1 (latest)
@primal zephyr 😳sorry for the tag
I appreciate you are sorry, but try to refrain as per the #✅┊rules
Provide the code please.
class MarineVehicleResource extends Resource
{
use Translatable;
protected static ?string $model = MarineVehicle::class;
public static function form(Form $form): Form
{
return $form->schema([
CheckboxList::make('marineVehiclePackage')
->translateLabel()
->options(MarineVehiclePackage::where('isActive', true)->pluck('name', 'id'))
->columns(2)
->gridDirection('row')
->searchable(),
]);
}
}
Actually, when I use the "Spatie Translatable" Plugin, the "CheckboxList" names do not appear
I'm sorry about that. I will pay attention to this
yep
Is the name a json column? name: "{"en":"xxx"}" ?
Are you using HasTranslations in the model?
{"en": "Test package name", "es": "Nombre del conjunto de pruebas"} Yes in json format
Yes, the room is attached.
Did you add HasTranslations to the model?
Yes
Would you like me to share the entire package with you?
what is the output if you remove HasTranslations ?
I save the data I want to show in the "CheckboxList" here. When I want to show it in the 2nd image, its name is not visible. When I remove "HasTranslations" from the model, I get the same result.
can you try using the fork:
https://github.com/lara-zeus/translatable
its working with me
make sure your model MarineVehiclePackage has the translatable trait and you defined the translatable attributes
Thanks so much for your time. This package worked. Now the names appear, but when the language is changed with "Switcher" there is no change.
in this case you will need to query the active locale:
->options(fn(Livewire $livewire) => MarineVehiclePackage::where('isActive', true)->whereLocale('name', $livewire->activeLocale)->pluck('name', 'id'))
and import
use Livewire\Component as Livewire;
This still doesn't work when I try to create a new page.
its working for me and this is my code:
CheckboxList::make('marineVehiclePackage')
->options(fn(Livewire $livewire) => Book::whereLocale('title', $livewire->activeLocale)->pluck('title', 'id')),
you do have the trait Translatable in the create page class?
test:
->options(fn(Livewire $livewire) => dd($livewire->activeLocale)),
Oh yes. If you want to take a look, it's here
what the output of
->options(fn(Livewire $livewire) => dd($livewire->activeLocale)),
it should return the active locale, when you switch
Actually, I do everything you say, but I can't get the result I want. Is there a chance you could share the source if you don't mind ?
this is the versions
I am using the fork lara-zeus/translatable
but I checked its also working with the filament/spatie-laravel-translatable-plugin/translatable
I tried everything you suggested again. But I still get the same result. I did as you said in the example below. When I show this on the new content creation page, the language selector does not show the result. I'm sharing the example if you want to check it out. Thank you very much for your time 😭
if you can share the code on a repo or git gist I will look into it
https://github.com/engbz/demo Thank you very much
my code didnt work on your app not sure why, but try this:
->options(function (Livewire $livewire) {
return Book::query()
->whereNotNull("title->{$livewire->activeLocale}")
->get()
->mapWithKeys(function($item) use($livewire){
return [$item->id=>$item->getTranslation('title',$livewire->activeLocale)];
});
})