Download the PHP package levgenij/filament-translatable without Composer
On this page you can find all versions of the php package levgenij/filament-translatable. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download levgenij/filament-translatable
More information about levgenij/filament-translatable
Files in levgenij/filament-translatable
Package filament-translatable
Short Description Automatic translation support for Filament Resources based on levgenij/laravel-translatable
License MIT
Homepage https://github.com/levgenij/filament-translatable
Informations about the package filament-translatable
Filament Translatable
Seamless multilingual support for Filament Resources with automatic translatable field generation based on levgenij/laravel-translatable.
📦 Version Compatibility
Please install the version that matches your Filament version:
| Filament Version | Package Version | Branch | Installation |
|---|---|---|---|
| Filament v5.x | ^2.0 |
main |
composer require levgenij/filament-translatable:^2.0 |
| Filament v3/v4 | ^1.0 |
v1 |
composer require levgenij/filament-translatable:^1.0 |
Note: This documentation is for Filament v5. If you are using Filament v3 or v4, please switch to the v1 documentation.
Features
- Zero Configuration - Translatable fields are detected automatically from the model
- Language Tabs - Fields are grouped into tabs for each locale
- Locale Badges - Visual indicators next to field labels:
Title [EN] - Missing Translation Badge - Locale tabs with only blank fields are marked with a badge
- Clean Form Schema - No wrappers or special syntax needed
- Single Locale Mode - No tabs or badges when only one locale is configured
- Filament 5 - Built for Filament 5 (Schema API)
Requirements
- PHP 8.2+
- Laravel 11+
- Filament 5.0+
- levgenij/laravel-translatable 3.0+
Installation
Install the package via Composer:
The package will auto-register its service provider.
Publish Configuration (Optional)
Quick Start
1. Configure Your Model
Your model must use the Translatable trait from levgenij/laravel-translatable:
2. Add Trait to Resource
3. Add Trait to Create/Edit Pages
CreateRecord:
EditRecord:
That's it! Your form will now automatically display translatable fields in language tabs.
Configuration
Locales
By default, the package reads locales from config/translatable.php (the parent package). You can override this in config/filament-translatable.php:
Badge Style
Customize the locale badge appearance:
Tab Label Format
Placeholders: {CODE} (uppercase locale code), {code} (lowercase locale code), {name} (native locale name).
Missing Translation Badge
A locale tab whose fields are all blank gets a badge with a "No translation" tooltip. Blank is decided by the same Blank Values rules as saving, applied to the field state with casts (a RichEditor document is checked as HTML). Field callbacks that run only on save, such as dehydrateStateUsing() or dehydrated(false), are not applied to the badge.
The marked tab also gets a data-missing-translation attribute. Filament adds the tab attributes to the tab button, the overflow dropdown item and the tab panel, so target the button to restyle the badge:
The tooltip text comes from the filament-translatable::translations.missing_translation translation key (English and Ukrainian are included). Override it with php artisan lang:publish or in lang/vendor/filament-translatable/{locale}/translations.php.
Blank Values
A locale whose fields are all blank is not stored, and on edit its existing row is removed. Define what counts as blank:
With strip_tags enabled, RichEditor custom blocks (<div data-type="customBlock">) and mentions (<span data-type="mention">) have no text, so a locale with only them is blank. Add div or span to content_tags when forms use them.
The same rules are available as TranslatableSchemaTransformer::isBlank($value).
How It Works
Architecture
Data Flow
-
Resource - The
TranslatableResourcetrait provides thegetTranslatableAttributes()method that reads the model's$translatableproperty. -
Page - The
HasTranslatableFieldstrait intercepts theform()method and transforms the schema:- Finds fields that exist in
$model->translatable - Groups them into language tabs (when multiple locales)
- Adds locale badges to labels
- Non-translatable fields remain unchanged
- Finds fields that exist in
-
Loading - The edit form shows only stored translation rows. A locale without a stored row stays empty: no fallback locale and no model accessors are applied.
- Saving - The trait automatically:
- Extracts translation data from the form
- Saves them via
$model->saveTranslation($locale, $data) - Skips a locale whose fields are all blank (see Blank Values) and deletes its existing row
Form Data Structure
Data in the form is stored in this structure:
UI Behavior
Multiple Languages
When multiple languages are configured, translatable fields are grouped into tabs:
Single Language
When only one language is configured:
- Tabs are not shown
- Badges are not shown
- Fields are displayed normally
Advanced Usage
Overriding mutateFormDataBeforeFill
If you need additional logic when filling the form:
Overriding mutateFormDataBeforeCreate/Save
Custom Validation
Validation works as expected. Field rules are copied to every locale tab.
unique() on a translatable field checks the translations table and is scoped to the field locale. With ignoreRecord: true the edited record's own translation is ignored:
The rule is only rewritten when it targets the model table and the field's own column (the default, or column set to the attribute name). With another table or column, or with a rule object passed to rule(), the rule is used as written.
Database Structure
The package works with levgenij/laravel-translatable which uses separate translation tables:
Troubleshooting
Fields are not transformed
Make sure that:
- Resource has
use TranslatableResource; - Page has
use HasTranslatableFields; - Model has
$translatableproperty with correct fields - Model uses
use Levgenij\LaravelTranslatable\Translatable
Translations are not saved
Make sure that:
- Table
{table}_translationsexists - Fields are in model's
$fillable - Fields are in model's
$translatable
Error "Call to undefined method saveTranslation"
Model does not use the Levgenij\LaravelTranslatable\Translatable trait.
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security
If you discover any security-related issues, please email [email protected] instead of using the issue tracker.
Credits
- Levgenij
- All Contributors
License
The MIT License (MIT). Please see License File for more information.