lara-zeus/spatie-translatable
Filament v4 plugin adding Spatie Laravel Translatable support to your admin panel. Includes default locales, locale switcher, translation on create/edit/list/view pages, per-resource locale settings, and translatable relation managers.
Install the plugin with Composer:
composer require lara-zeus/spatie-translatable
To add a plugin to a panel, you must include it in the configuration file using the plugin() method:
use LaraZeus\SpatieTranslatable\SpatieTranslatablePlugin;
public function panel(Panel $panel): Panel
{
return $panel
// ...
->plugin(SpatieTranslatablePlugin::make());
}
to remember the user's selected locale throughout their session, you can pass the method persist()
use LaraZeus\SpatieTranslatable\SpatieTranslatablePlugin;
public function panel(Panel $panel): Panel
{
return $panel
// ...
->plugin(
SpatieTranslatablePlugin::make()
->persist(),
);
}
To set up the locales that can be used to translate content, you can pass an array of locales to the defaultLocales() plugin method:
use LaraZeus\SpatieTranslatable\SpatieTranslatablePlugin;
public function panel(Panel $panel): Panel
{
return $panel
// ...
->plugin(
SpatieTranslatablePlugin::make()
->defaultLocales(['en', 'es']),
);
}
You need to make your model translatable. You can read how to do this in Spatie's documentation.
You must apply the LaraZeus\SpatieTranslatable\Resources\Concerns\Translatable trait to your resource class:
use LaraZeus\SpatieTranslatable\Resources\Concerns\Translatable;
use Filament\Resources\Resource;
class BlogPostResource extends Resource
{
use Translatable;
// ...
}
How can I help you explore Laravel packages today?