PHP code example of filamerce / filament-translatable

1. Go to this page and download the library: Download filamerce/filament-translatable 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/ */

    

filamerce / filament-translatable example snippets


use Filamerce\FilamentTranslatable\Enums\TranslationMode;

FilamentTranslatablePlugin::make()
    ->translationMode(TranslationMode::Astrotomic)

 Translations::make('translations')
    ->translationMode(TranslationMode::Astrotomic)

 TextInput::make('name')
    ->translatable()
    ->translationMode(TranslationMode::Astrotomic)

use Filamerce\FilamentTranslatable\FilamentTranslatablePlugin;

public function panel(Panel $panel): Panel
{
    return $panel
        // ...
        ->plugin(FilamentTranslatablePlugin::make());
}

FilamentTranslatablePlugin::make()
     ->locales(['en', 'pl', 'fr']),

FilamentTranslatablePlugin::make()
    ->locales([
        'pl' => __('Polish'),
        'en' => __('English')
    ])

FilamentTranslatablePlugin::make()
    ->locales(fn () => Language::pluck('code', 'name'))

FilamentTranslatablePlugin::make()
     ->defaultLocale('pl'),

FilamentTranslatablePlugin::make()
    ->displayFlagsInLocaleLabels(true)

FilamentTranslatablePlugin::make()
    ->flagWidth('24px')

FilamentTranslatablePlugin::make()
    ->displayNamesInLocaleLabels(false)

use Filament\Forms\Components\TextInput;

TextInput::make('name')
    ->translatable()

use Filament\Forms\Components\TextInput;

TextInput::make('name')
    ->

use Filament\Forms\Components\TextInput;

TextInput::make('name')
    ->

use Filament\Forms\Components\TextInput;

TextInput::make('price')
    ->decorateTranslationField('pl', fn (TextInput $field) => $field->suffix('PLN'))
    ->decorateTranslationField('en', fn (TextInput $field) => $field->prefix('USD')),
    ->translatable()

use Filament\Forms\Components\TextInput;

TextInput::make('price')
    ->lations component
    ->vertical()
    ->displayFlagsInLocaleLabels(true)
    ->displayNamesInLocaleLabels(false)
    ->flagWidth('48px')

use Filamerce\FilamentTranslatable\Forms\Component\Translations;

Translations::make('translations') // name is 

Translations::make('translations')
    ->locales(['en', 'es'])

use Filamerce\FilamentTranslatable\Forms\Component\Translations;

 Translations::make()
    ->schema([
        // Fields
    ])
    ->fieldTranslatableLabel(fn ($field, $locale) => __($field->getName(), locale: $locale))

use Filamerce\FilamentTranslatable\Forms\Component\Translations;

Translations::make('translations')
    ->schema([
        // Fields
    ])
    ->prefixLocaleLabel()
    ->suffixLocaleLabel()

use Filamerce\FilamentTranslatable\Forms\Component\Translations;

Translations::make('translations')
    ->preformLocaleLabelUsing(fn (string $locale, string $label) => "[{$label}]");

use Filament\Forms\Components\Component;
use Filamerce\FilamentTranslatable\Forms\Component\Translations;

Translations::make('translations')
    // ...
    ->prefixLocaleLabel(function(Component $field) {
        // need return boolean value
        return $field->getName() == 'title';
    })
    ->suffixLocaleLabel(function(Component $field) {
        // need return boolean value
        return $field->getName() == 'title';
    })



use Filament\Forms\Components\Actions\Action;
use Filamerce\FilamentTranslatable\Forms\Component\Translations;

Translations::make('translations')
    ->actions([
        Action::make('fillDumpTitle')
    ])


use Filament\Forms\Components\Actions\Action;
use Filamerce\FilamentTranslatable\Forms\Component\Translations;

Translations::make()
    ->actions([
        Action::make('fillDumpTitle')
            ->action(function (array $arguments) {
                $locale = $arguments['locale'];
                // ...
            })
    ])


use Filament\Forms\Components\TextInput;
use Filamerce\FilamentTranslatable\Forms\Component\Translations;

Translations::make()
    ->schema(fn (string $locale) => [TextInput::make('title')->

use Filamerce\FilamentTranslatable\Forms\Component\Translations;
 
Translations::make()
    ->contained(false)

use Filamerce\FilamentTranslatable\Forms\Component\Translations;
 
Translations::make()
    ->vertical()

use Filamerce\FilamentTranslatable\Forms\Component\Translations;
 
Translations::make()
    ->displayNamesInLocaleLabels(false)
    ->displayFlagsInLocaleLabels(true)
    ->flagWidth('48px')

use Filamerce\FilamentTranslatable\Forms\Component\Translations;
 
Translations::make('translations')
    ->schema([
        Forms\Components\TextInput::make('title'),
        Forms\Components\TextInput::make('description'),
    ])
    ->exclude(['description'])
bash
php artisan filament:assets
json
{
    "title": {
        "en": "Dump",
        "es": "Dump",
        "fr": "Dump"
    },
    "description": {
        "en": null,
        "es": null,
        "fr": null
    }
}
bash
php artisan vendor:publish --provider="Filamerce\\FilamentTranslatable\\FilamentTranslatableProvider" --tag="filament-translatable-views"