34ml / filament-translatable-field
A laravel filament field that handle translation
Installs: 1 162
Dependents: 0
Suggesters: 0
Security: 0
Stars: 17
Watchers: 3
Forks: 1
Open Issues: 0
Requires
- php: ^8.1 | ^8.2
- filament/filament: ^3.0
- illuminate/contracts: *
- spatie/laravel-package-tools: ^1.14.0
- spatie/laravel-translatable: *
Requires (Dev)
- laravel/pint: ^1.0
- nunomaduro/collision: ^7.9
- nunomaduro/larastan: ^2.0.1
- orchestra/testbench: ^8.0
- pestphp/pest: ^2.0
- pestphp/pest-plugin-arch: ^2.0
- pestphp/pest-plugin-laravel: ^2.0
- phpstan/extension-installer: ^1.1
- phpstan/phpstan-deprecation-rules: ^1.0
- phpstan/phpstan-phpunit: ^1.0
- spatie/laravel-ray: ^1.26
README
This package enables you to implement the following:
- Render a language selector to change the localized field
- You can save your localized fields data in one click
- You can use it in your relationship manager to show the localized fields
This package depends on spatie/laravel-translatable, Please check it first to set up your translation logic in your project.
Installation
You can install the package via composer:
composer require 34ml/filament-translatable-field
You can publish the config file with:
php artisan vendor:publish --tag="filament-translatable-field-config"
This is the content of the published config file where fields are created for each language listed here
return [ 'locales' => [ 'en' => 'English', 'ar' => 'Arabic', ], 'select_translation_field_name' => 'select_language', ];
Translatable Field Usage
Basic Usage
- Just add the field in your resource, view, create,or edit pages inside the form function
..._34ML\FilamentTranslatableField::make( 'your_translatable_field_name', \Filament\Forms\Components\TextInput::class, // The field type class )
- If you want to customize the label of the field
..._34ML\FilamentTranslatableField::make( 'your_translatable_field_name', \Filament\Forms\Components\TextInput::class, // The field type class 'your_field_displayed_name', // Optional )
- If you want to add filament field functions
..._34ML\FilamentTranslatableField::make( 'your_translatable_field_name', \Filament\Forms\Components\TextInput::class, // The field type class // add your filament field functions as a callback, you can add it as one function callbacks: function (){ $this->required(); $this->numeric(); return $this; // You have to return the field or the callbacks won't work } )
Language Selector
If you want to add a language selector that shows only the selected language's fields instead of showing all fields you can simply add this field in your resource, view, create,or edit pages inside the form function
use _34ML\FilamentTranslatableField\Forms\Components\LanguageSelector; return $form ->schema([ LanguageSelector::make(), ]);
Relationship Manager
you need to add this code to your relationship manager
public static function getRecordTitle(?Model $record): ?string { return $record->getTranslation('your_title_column', config('filament-translatable-field.locales')[0]); }
Credits
License
The MIT License (MIT). Please see License File for more information.