What I’m trying to do:
Make a custom Filament v3 Page translatable using spatie/laravel-translatable. I want the user to switch languages and edit localized values.
What I did:
- My
Settingmodel usesHasTranslationsand stores JSON values correctly. - My
PageusesTranslatabletrait. - Locale switcher appears via
Actions\LocaleSwitcher::make(). - The form has inputs like
TextInput::make('html_title'),RichEditor::make('footer_descript'), etc.
The issue:
Switching the language via the locale switcher does not change the form input values.
Everything stays in the default locale. No errors in console or logs.
Expected: When switching to e.g. en, the form should load html_title and others in English.
Code snippet:
class Settings extends Page implements HasForms
{
use InteractsWithForms, Translatable;
public ?array $data = [];
public function mount(): void
{
$this->form->fill([
'html_title' => Setting::get('html_title'),
'footer_descript' => Setting::get('footer_descript'),
]);
}
public function form(Form $form): Form
{
return $form
->statePath('data')
->schema([
TextInput::make('html_title')->label('HTML title'),
RichEditor::make('footer_descript')->label('Footer'),
]);
}
public function save(): void
{
foreach ($this->form->getState() as $key => $value) {
Setting::updateOrCreate(['key' => $key], ['value' => $value]);
}
}
protected function getHeaderActions(): array
{
return [ Actions\LocaleSwitcher::make() ];
}
}
Note:
This is a custom Page, not a Resource.
Model translation works fine outside Filament.
But in this Page form, switching language doesn’t affect input values.
Any ideas what I’m missing?
Thanks!