PHP code example of asignua / filament-translatable-fields

1. Go to this page and download the library: Download asignua/filament-translatable-fields library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

asignua / filament-translatable-fields example snippets


use Spatie\Translatable\HasTranslations;

class Post extends Model
{
    use HasTranslations;

    public array $translatable = ['title', 'body'];
}

use Asignua\FilamentTranslatableFields\Forms\Translatable;
use Asignua\FilamentTranslatableFields\Forms\TranslatableTabs;

// A factory: you build the input for each language.
TranslatableTabs::make('title', fn (string $locale) => TextInput::make('title')->maxLength(255))
    ->

Repeater::make('items')->schema([
    TextInput::make('sku'),
    Translatable::field(TextInput::make('label')),          // JSON column: items.{uuid}.label.{locale}
]),

Builder::make('blocks')->blocks([
    Builder\Block::make('heading')->schema([
        Translatable::field(TextInput::make('text')),
    ]),
]),

Repeater::make('sections')->relationship()->orderColumn('sort')->schema([
    Translatable::field(TextInput::make('heading')),        // Section uses HasTranslations
]),

use Asignua\FilamentTranslatableFields\Concerns\HandlesTranslatableFields;

class EditPost extends EditRecord
{
    use HandlesTranslatableFields;
}

TranslatableColumn::make('title')->searchAcrossLocales()->sortableByLocale(),
TranslatableColumn::make('team.name')->marker(false),
TranslatableEntry::make('title'),

// config/filament-translatable-fields.php
'locales' => null,         // null → your app's translatable.locales, if defined → [app.locale, app.fallback_locale]
'default_locale' => null,  // null → app.locale (or the first language)
'labels' => [],            // ['uk' => 'Українська']; default: the language's own name (intl) or the code
'marker' => '[:locale] ',  // '' disables the marker
'empty_badges' => false,   // opt-in: the inputs become live(onBlur: true) to keep the badge current

TranslatableFields::locales(['uk', 'en', 'pl']);   // or a closure
TranslatableFields::defaultLocale('uk');
TranslatableFields::labels(['pl' => 'Polski']);
bash
php artisan vendor:publish --tag="filament-translatable-fields-config"