Download the PHP package outerweb/filament-translatable-fields without Composer
On this page you can find all versions of the php package outerweb/filament-translatable-fields. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download outerweb/filament-translatable-fields
More information about outerweb/filament-translatable-fields
Files in outerweb/filament-translatable-fields
Package filament-translatable-fields
Short Description Filament integration for spatie/laravel-translatable
License MIT
Homepage https://github.com/outerweb/filament-translatable-fields
Informations about the package filament-translatable-fields
Filament Translatable Fields
This Filament plugin provides an integration for the spatie/laravel-translatable package.
It can easily be combined with the lara-zeus/translatable package as our package only provides the Form integration. To do so, simply remove all lara-zeus specific code from the Create and Edit pages of your Filament Resources.
Instead of rendering a dropdown to select the locale, it wraps the translatable fields in a Tabs component for a better user experience.
⚠️ Caution: V4 is a complete rewrite of the package and logic. Please take a look at the installation instructions below!
Table of Contents
- Installation
- Configuration
- Usage
- Changelog
- License
Installation
You can install the package via composer:
Add the plugin to your panel:
Configuration
Supported locales
By default, the package will try to read out the supported locales from the config/app.php file. It will check for app.supported_locales first and then fallback to app.locales and app.fallback_locale.
You can manually configure the supported locales like this:
If you want to provide custom labels for the locales, you can do it like this:
If you want to dynamically provide the supported locales, you can also pass a Closure to the supportedLocales() method:
Default locale
By default, the active tab will be the one of the app's locale when rendering the form. You can change this behavior by setting a default locale:
If you want to dynamically provide the default locale, you can also pass a Closure to the defaultLocale() method:
Usage
Marking single fields as translatable
To mark a single field as translatable, you can use the translatable() method on any Filament form field:
This will wrap the field in a Tabs component with a tab for each supported locale.
Note: Make sure to place the
translatable()method at the end of the field definition to avoid any unexpected behavior.
Modifying/Validating a field for a specific locale
All modifiers and validation rules applied before calling the translatable() method will be applied field for each locale. If you want to apply a modifier or validation rule for a specific locale only, you can use the modifyLocalizedFieldUsing parameter in the translatable() method:
Conditionally marking a field as translatable
You can also conditionally mark a field as translatable by passing a bool or Closure to the translatable() method:
Overriding the supported locales for a single field
You can override the supported locales for a single field by passing an array or Closure to the translatable() method:
Overriding the default locale for a single field
You can override the default locale for a single field by passing a string or Closure to the translatable() method:
Marking a group of fields as translatable
You can also mark a Layout component as translatable. This will make all fields inside the layout translatable:
This will wrap all fields inside the layout in a Tabs component with a tab for each supported locale.
Note: Make sure to place the
translatable()method at the end of the component definition to avoid any unexpected behavior.
All the options described for single fields (modifying/validating a field for a specific locale, conditionally marking as translatable, overriding supported/default locales) are also available when marking a layout component as translatable.
For modifying/validating fields inside a layout component, the provided Closure will be called for each field inside the layout.
Example:
Changelog
Please see CHANGELOG for more information on what has changed recently.
License
The MIT License (MIT). Please see License File for more information.
All versions of filament-translatable-fields with dependencies
filament/filament Version ^4.0|^5.0
spatie/laravel-package-tools Version ^1.16
spatie/laravel-translatable Version ^6.12