ster / filament-translatable-fields

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Filament Translatable Fields

Latest Version on Packagist Total Downloads

This package adds a way to make all filament fields translatable. It uses the spatie/laravel-translatable package in the background.

Installation

You can install the package via composer:

composer require outerweb/filament-translatable-fields

Add the plugin to your desired Filament panel:

use OuterWeb\FilamentTranslatableFields\Filament\Plugins\FilamentTranslatableFieldsPlugin;

class FilamentPanelProvider extends PanelProvider
{
    public function panel(Panel $panel): Panel
    {
        return $panel
            // ...
            ->plugins([
                FilamentTranslatableFieldsPlugin::make(),
            ]);
    }
}

You can specify the supported locales:

use OuterWeb\FilamentTranslatableFields\Filament\Plugins\FilamentTranslatableFieldsPlugin;

class FilamentPanelProvider extends PanelProvider
{
    public function panel(Panel $panel): Panel
    {
        return $panel
            // ...
            ->plugins([
                FilamentTranslatableFieldsPlugin::make()
                    ->supportedLocales([
                        'en' => 'English',
                        'nl' => 'Dutch',
                    ]),
            ]);
    }
}

By default, the package will use the app.locale if you don't specify the locales.

Usage

You can simply add ->translatable() to any field to make it translatable.

use Filament\Forms\Components\TextInput;

TextInput::make('name')
    ->label('Name')
    ->translatable(),

Good to know

This package will substitute the original field with a Filament\Forms\Components\Tabs component. This component will render the original field for each locale.

All chained methods you add before calling ->translatable() will be applied to the original field. All chained methods you add after calling ->translatable() will be applied to the Filament\Forms\Components\Tabs component.

Changelog

Please see CHANGELOG for more information on what has changed recently.

Credits

License

The MIT License (MIT). Please see License File for more information.

About

License:MIT License


Languages

Language:PHP 100.0%