{"id":23219196,"url":"https://github.com/solutionforest/filament-translate-field","last_synced_at":"2026-04-29T10:08:14.382Z","repository":{"id":215379482,"uuid":"738459713","full_name":"solutionforest/filament-translate-field","owner":"solutionforest","description":"Filament Translate Field is a library for Filament CMS that simplifies managing multiple translatable fields in different languages.","archived":false,"fork":false,"pushed_at":"2026-04-22T10:05:50.000Z","size":218,"stargazers_count":47,"open_issues_count":7,"forks_count":17,"subscribers_count":3,"default_branch":"3.x","last_synced_at":"2026-04-22T12:12:39.401Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/solutionforest.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2024-01-03T09:25:14.000Z","updated_at":"2026-04-22T10:04:21.000Z","dependencies_parsed_at":null,"dependency_job_id":"720efb29-3e47-49d8-a211-7da8b7d23a5e","html_url":"https://github.com/solutionforest/filament-translate-field","commit_stats":null,"previous_names":["solutionforest/filament-translate-field"],"tags_count":17,"template":false,"template_full_name":null,"purl":"pkg:github/solutionforest/filament-translate-field","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/solutionforest%2Ffilament-translate-field","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/solutionforest%2Ffilament-translate-field/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/solutionforest%2Ffilament-translate-field/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/solutionforest%2Ffilament-translate-field/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/solutionforest","download_url":"https://codeload.github.com/solutionforest/filament-translate-field/tar.gz/refs/heads/3.x","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/solutionforest%2Ffilament-translate-field/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32420469,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-29T06:29:02.080Z","status":"ssl_error","status_checked_at":"2026-04-29T06:29:00.631Z","response_time":110,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-18T21:20:06.951Z","updated_at":"2026-04-29T10:08:14.370Z","avatar_url":"https://github.com/solutionforest.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Filament Translate Field\n\n[![Latest Version on Packagist](https://img.shields.io/packagist/v/solution-forest/filament-translate-field.svg?style=flat-square)](https://packagist.org/packages/solution-forest/filament-translate-field)\n[![Total Downloads](https://img.shields.io/packagist/dt/solution-forest/filament-translate-field.svg?style=flat-square)](https://packagist.org/packages/solution-forest/filament-translate-field)\n\nFilament Translate Field is a library for Filament CMS that simplifies managing multiple translatable fields in different languages.\n\n![filament-translate-field-1](https://github.com/solutionforest/filament-translate-field/assets/68525320/34c74a8f-fd8e-4db6-a967-31deecdf113b)\n\n## Installation\n\n| Filament Version | Filament Translate Field Version |\n| ---------------- | -------------------------------- |\n| v3.x             | v0.x – v1.x                      |\n| v4.x             | v2.x                             |\n| v5.x             | v3.x                             |\n\nYou can install the package via composer:\n\n```bash\ncomposer require solution-forest/filament-translate-field\n```\n\nPublish the assets:\n\n```bash\nphp artisan filament:assets\n```\n\n```bash\nphp artisan optimize\n```\n\n## Important\n\n-   There's a conflict with the Translatable trait in the [filament/spatie-laravel-translatable-plugin](https://filamentphp.com/plugins/filament-spatie-translatable) when used on the EditPage. Avoid using Translatable while editing.\n\n## Configuration:\n\n-   Define translatable fields in your model using a translatable package (e.g., \"spatie/laravel-translatable\" or \"dimsav/laravel-translatable\").\n-   Configure translatable fields in the model's _$translatable_ property.\n\n## Setup\n\n\u003cdetails\u003e\n \u003csummary\u003e\u003cb\u003eFor version before 1.x.x\u003c/b\u003e\u003c/summary\u003e\n  \u003ch3\u003e Adding the plugin to a panel\u003c/h3\u003e\n  \n \u003cp\u003eTo add a plugin to a panel, you must include it in the configuration file using the plugin() method:\u003c/p\u003e\n \n  ```php\n  use SolutionForest\\FilamentTranslateField\\FilamentTranslateFieldPlugin;\n   \n  public function panel(Panel $panel): Panel\n  {\n      return $panel\n          // ...\n          -\u003eplugin(FilamentTranslateFieldPlugin::make());\n  }\n  ```\n  \n \u003ch3\u003e Setting the default translatable locales \u003c/h3\u003e\n \n  \u003cp\u003eTo set up the locales that can be used to translate content, you can pass an array of locales to the `defaultLocales()` plugin method:\u003c/p\u003e\n  \n  ```php\n  use SolutionForest\\FilamentTranslateField\\FilamentTranslateFieldPlugin;\n   \n  public function panel(Panel $panel): Panel\n  {\n      return $panel\n          // ...\n          -\u003eplugin(\n              FilamentTranslateFieldPlugin::make()\n                 -\u003edefaultLocales(['en', 'es', 'fr']),\n          );\n  }\n  ```\n\u003c/details\u003e\n\n\u003cdetails open\u003e\n \u003csummary\u003e\u003cb\u003eFor version equal or after 1.x.x\u003c/b\u003e\u003c/summary\u003e\n \n \u003ch3\u003e Setting the default translatable locales \u003c/h3\u003e\n\n \u003cp\u003eSince the plugin after 1.x.x is a standalone plugin, which does not need to be related to Filament Panel, so you need to globally set it up in the config file or use the boot method in `AppServiceProvider`.\u003c/p\u003e\n  \u003cp\u003eTo set up the locales that can be used to translate content, you can pass an array of locales to the `defaultLocales()` plugin method:\u003c/p\u003e\n  \n  ```php\n  use SolutionForest\\FilamentTranslateField\\Facades\\FilamentTranslateField;\n   \n  class AppServiceProvider extends ServiceProvider\n {\n     public function boot(): void\n     {\n         FilamentTranslateField::defaultLocales(['en', 'es', 'fr']);\n     }\n }\n  ```\n\nOr, you can publish configuration file `config/filament-translate-field.php` and add default locales on `locales`:\n\n```php\n\nreturn [\n    'locales' =\u003e ['en', 'es', 'fr'],\n];\n```\n\n\u003c/details\u003e\n\n## Usage\n\n### Form component\n\nBy using the `Translate` component, you can easily configure your [form fields](https://filamentphp.com/docs/3.x/forms/fields/getting-started) to support multiple languages and provide translations for each locale.\n\n```php\nuse Filament\\Forms\\Components\\TextInput;\nuse Filament\\Forms\\Components\\Textarea;\nuse Filament\\Forms\\Components\\RichEditor;\nuse SolutionForest\\FilamentTranslateField\\Forms\\Component\\Translate;\n\nTranslate::make()\n    -\u003eschema([\n         // Your form fields here\n    ])\n```\n\n#### Setting the translatable locales for a particular fields\n\nBy default, the translatable locales can be set globally for all translate form component in the plugin configuration. Alternatively, you can customize the translatable locales for a particular resource by overriding the `locales()` method in `Translate` class:\n\n```php\nuse SolutionForest\\FilamentTranslateField\\Forms\\Component\\Translate;\n\nTranslate::make()-\u003elocales(['en', 'es'])\n```\n\n#### Label\n\n##### Setting the translatable label for a particular field\n\nYou have the flexibility to customize the translate label for each field in each locale. You can use the `fieldTranslatableLabel()` method to provide custom labels based on the field instance and the current locale.\n\n```php\nuse SolutionForest\\FilamentTranslateField\\Forms\\Component\\Translate;\n\n Translate::make()\n    -\u003eschema([\n        // Fields\n    ])\n    -\u003efieldTranslatableLabel(fn ($field, $locale) =\u003e __($field-\u003egetName(), locale: $locale))\n```\n\n##### Adding prefix/suffix locale label to the field\n\nIf you simply want to add a prefix or suffix locale label to the form field, you can use the `prefixLocaleLabel()` or `suffixLocaleLabel()` method. This makes it easier for users to identify the language associated with each field.\n\n```php\nuse SolutionForest\\FilamentTranslateField\\Forms\\Component\\Translate;\n\nTranslate::make()\n    -\u003eschema([\n        // Fields\n    ])\n    -\u003eprefixLocaleLabel()\n    -\u003esuffixLocaleLabel()\n```\n\n\u003e `prefixLocaleLabel:\n\u003e\n\u003e ![filament-translate-field-3](https://github.com/solutionforest/filament-translate-field/assets/68525320/0203e682-f324-4957-8680-4cffccab300c)\n\n\u003e `suffixLocaleLabel`:\n\u003e\n\u003e ![filament-translate-field-4](https://github.com/solutionforest/filament-translate-field/assets/68525320/7f4403e9-c857-4ebf-b022-8fed12094426)\n\n#### Setting the locale display name\n\nBy default, the prefix/suffix locale display name is generated by locale code and enclosed in parentheses, \"()\". You may customize this using the `preformLocaleLabelUsing()` method:\n\n```php\nuse SolutionForest\\FilamentTranslateField\\Forms\\Component\\Translate;\n\nTranslate::make()\n    -\u003epreformLocaleLabelUsing(fn (string $locale, string $label) =\u003e \"[{$label}]\");\n```\n\n#### Injecting the current form field\n\nAdditionally, if you need to access the current form field instance, you can inject the `$field` parameter into the callback functions. This allows you to perform specific actions or conditions based on the field being processed.\n\n```php\nuse Filament\\Forms\\Components\\Component;\nuse SolutionForest\\FilamentTranslateField\\Forms\\Component\\Translate;\n\nTranslate::make()\n    // ...\n    -\u003eprefixLocaleLabel(function(Component $field) {\n        // need return boolean value\n        return $field-\u003egetName() == 'title';\n    })\n    -\u003esuffixLocaleLabel(function(Component $field) {\n        // need return boolean value\n        return $field-\u003egetName() == 'title';\n    })\n\n```\n\n![filament-translate-field-5](https://github.com/solutionforest/filament-translate-field/assets/68525320/a88fcb69-a63d-43a6-857b-5323df877134)\n\n### Adding action\n\nYou may add actions before each container of children components using the `actions()` method:\n\n```php\n\nuse Filament\\Forms\\Components\\Actions\\Action;\nuse SolutionForest\\FilamentTranslateField\\Forms\\Component\\Translate;\n\nTranslate::make()\n    -\u003eactions([\n        Action::make('fillDumpTitle')\n    ])\n```\n\n\u003e _If have multiple `Translate` components and have action in each component, please add id to `Translate` component by `id()` method_\n\n#### Injecting the locale on current child container\n\nIf you wish to access the locale that have been passed to the action, define an `$arguments` parameter and get the value of `locale` from `$arguments`:\n\n```php\n\nuse Filament\\Forms\\Components\\Actions\\Action;\nuse SolutionForest\\FilamentTranslateField\\Forms\\Component\\Translate;\n\nTranslate::make()\n    -\u003eactions([\n        Action::make('fillDumpTitle')\n            -\u003eaction(function (array $arguments) {\n                $locale = $arguments['locale'];\n                // ...\n            })\n    ])\n```\n\n### Injecting the locale to form field\n\nIf you wish to access the current locale instance for the field, define a `$locale` parameter:\n\n```php\n\nuse Filament\\Forms\\Components\\TextInput;\nuse SolutionForest\\FilamentTranslateField\\Forms\\Component\\Translate;\n\nTranslate::make()\n    -\u003eschema(fn (string $locale) =\u003e [TextInput::make('title')-\u003erequired($locale == 'en')])\n```\n\n### Removing the styled container\n\nBy default, translate component and their content are wrapped in a container styled as a card. You may remove the styled container using `contained()`:\n\n```php\nuse SolutionForest\\FilamentTranslateField\\Forms\\Component\\Translate;\n\nTranslate::make()\n    -\u003econtained(false)\n```\n\n### Exclude\n\nThe `exclude` feature allows you to specify fields that you don't want to be included in the translation process. This can be useful for fields that contain dynamic content or that shouldn't be translated into other languages.\n\n```php\nuse SolutionForest\\FilamentTranslateField\\Forms\\Component\\Translate;\n\nTranslate::make([\n        Forms\\Components\\TextInput::make('title'),\n        Forms\\Components\\TextInput::make('description'),\n    ])\n    -\u003eexclude(['description'])\n```\n\nWithout exclude\n\n```json\n{\n    \"title\": {\n        \"en\": \"Dump\",\n        \"es\": \"Dump\",\n        \"fr\": \"Dump\"\n    },\n    \"description\": {\n        \"en\": null,\n        \"es\": null,\n        \"fr\": null\n    }\n}\n```\n\nWith Exclude\n\n```json\n{\n    \"title\": {\n        \"en\": \"Dump\",\n        \"es\": \"Dump\",\n        \"fr\": \"Dump\"\n    },\n    \"description\": null\n}\n```\n\n## Publishing Views\n\nTo publish the views, use:\n\n```bash\nphp artisan vendor:publish --provider=\"SolutionForest\\\\FilamentTranslateField\\\\FilamentTranslateFieldServiceProvider\" --tag=\"filament-translate-field-views\"\n```\n\n## Publishing Configuration file\n\nTo publish the configuration file, use:\n\n```bash\nphp artisan vendor:publish --provider=\"SolutionForest\\\\FilamentTranslateField\\\\FilamentTranslateFieldServiceProvider\" --tag=\"filament-translate-field-config\"\n```\n\n## Example\n\n### Demo\n\nhttps://github.com/solutionforest/filament-translate-field/assets/68525320/b088d632-2df5-4594-b91c-56b708425e41\n\n### Sample Code\n\nIn Filament panel:\n\n```php\nuse SolutionForest\\FilamentTranslateField\\FilamentTranslateFieldPlugin;\n\npublic function panel(Panel $panel): Panel\n{\n    return $panel\n        // ...\n            -\u003eplugin(FilamentTranslateFieldPlugin::make()\n                -\u003edefaultLocales(['en', 'es', 'fr'])\n            );\n}\n```\n\nIn app/Filament/Resources/NewsResource.php:\n\n```php\nuse Filament\\Forms;\nuse Filament\\Forms\\Components\\TextInput;\nuse Filament\\Forms\\Components\\Textarea;\nuse Filament\\Forms\\Components\\RichEditor;\nuse Filament\\Resources\\Resource;\nuse SolutionForest\\FilamentTranslateField\\Forms\\Component\\Translate;\n\nclass NewsResource extends Resource\n{\n    // ...\n\n    public static function form(Form $form): Form\n    {\n        return $form\n            -\u003eschema([\n                Translate::make()\n                    -\u003ecolumnSpanFull()\n                    -\u003ecolumns(2)\n                    -\u003eschema([\n                        TextInput::make('title')-\u003erequired(),\n                        Textarea::make('short_desc'),\n                        RichEditor::make('description')-\u003ecolumnSpanFull(),\n                    ])\n                    -\u003efieldTranslatableLabel(fn ($field, $locale) =\u003e __($field-\u003egetName(), locale: $locale))\n                    -\u003eactions([\n                        Forms\\Components\\Actions\\Action::make('test')\n                            -\u003elabel(\"Fill dump title\")\n                            -\u003evisible(fn ($arguments) =\u003e $arguments['locale']  == 'en')\n                            -\u003eaction(function ($set, $arguments) {\n                                $locale = $arguments['locale'] ?? null;\n                                if (! $locale) {\n                                    return;\n                                }\n                                $set(\"title.$locale\", fake()-\u003etext(50));\n                            })\n                    ]),\n            ]);\n    }\n\n    public static function table(Table $table): Table\n    {\n        return $table\n            -\u003ecolumns([\n\n                Tables\\Columns\\ColumnGroup::make('Data')\n                    -\u003ecolumns([\n                        Tables\\Columns\\TextColumn::make('title')\n                            -\u003egetStateUsing(fn ($record) =\u003e new HtmlString(collect($record-\u003etitle)\n                                -\u003emap(fn ($state, $locale) =\u003e \u003c\u003c\u003cHtml\n                                    \u003cdiv class=\"flex gap-2\"\u003e\n                                        \u003cdiv class=\"text-sm text-gray-500\"\u003e$locale\u003c/div\u003e\n                                        \u003cdiv\u003e$state\u003c/div\u003e\n                                    \u003c/div\u003e\n                                Html)\n                                -\u003eimplode(''))),\n                        Tables\\Columns\\TextColumn::make('short_desc')\n                            -\u003egetStateUsing(fn ($record) =\u003e new HtmlString(collect($record-\u003eshort_desc)\n                                -\u003emap(fn ($state, $locale) =\u003e \u003c\u003c\u003cHtml\n                                    \u003cdiv class=\"flex gap-2\"\u003e\n                                        \u003cdiv class=\"text-sm text-gray-500\"\u003e$locale\u003c/div\u003e\n                                        \u003cdiv\u003e$state\u003c/div\u003e\n                                    \u003c/div\u003e\n                                Html)\n                                -\u003eimplode(''))),\n                        Tables\\Columns\\TextColumn::make('description')\n                            -\u003egetStateUsing(fn ($record) =\u003e new HtmlString(collect($record-\u003edescription)\n                                -\u003emap(fn ($state, $locale) =\u003e \u003c\u003c\u003cHtml\n                                    \u003cdiv class=\"flex gap-2\"\u003e\n                                        \u003cdiv class=\"text-sm text-gray-500\"\u003e$locale\u003c/div\u003e\n                                        \u003cdiv\u003e$state\u003c/div\u003e\n                                    \u003c/div\u003e\n                                Html)\n                                -\u003eimplode(''))),\n                    ]),\n            ])\n            -\u003eactions([\n                Tables\\Actions\\EditAction::make(),\n                Tables\\Actions\\DeleteAction::make(),\n            ]);\n    }\n\n    // ...\n}\n```\n\nIn app/Models/News.php:\n\n```php\nuse Illuminate\\Database\\Eloquent\\Model;\nuse Spatie\\Translatable\\HasTranslations;\n\nclass News extends Model\n{\n    use HasTranslations;\n    // ...\n\n    protected $guarded = ['id'];\n\n    public $translatable = ['title', 'short_desc', 'description'];\n\n    public $casts = [\n        'title' =\u003e 'json',\n        'short_desc' =\u003e 'json',\n        'description' =\u003e 'json',\n    ];\n\n    // ...\n}\n```\n\nIn resources/lang/en.json:\n\n```json\n{\n    \"title\": \"Title\",\n    \"short_desc\": \"Short description\",\n    \"description\": \"Description\"\n}\n```\n\nIn resources/lang/es.json:\n\n```json\n{\n    \"title\": \"Título\",\n    \"short_desc\": \"Breve descripción\",\n    \"description\": \"Descripción\"\n}\n```\n\nIn resources/lang/fr.json:\n\n```json\n{\n    \"title\": \"Titre\",\n    \"short_desc\": \"Brève description\",\n    \"description\": \"Description\"\n}\n```\n\nIn the given example, when you save the model, the data will be stored in the following format:\n\n```json\n{\n    \"id\": 1,\n    \"title\": {\n        \"en\": \"Dump\",\n        \"es\": \"Dump\",\n        \"fr\": \"Dump\"\n    },\n    \"short_desc\": {\n        \"en\": null,\n        \"es\": null,\n        \"fr\": null\n    },\n    \"description\": {\n        \"en\": null,\n        \"es\": null,\n        \"fr\": null\n    }\n}\n```\n\n## Testing\n\n```bash\ncomposer test\n```\n\n## Changelog\n\nSee the [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.\n\n## Contributing\n\nSee [CONTRIBUTING](.github/CONTRIBUTING.md) for details.\n\n## Security Vulnerabilities\n\nIf you discover any security related issues, please email info+package@solutionforest.net instead of using the issue tracker.\n\n## Credits\n\n-   [Carly]\n-   [All Contributors](../../contributors)\n\n## License\n\nFilament Tree is open-sourced software licensed under the [MIT license](LICENSE.md).\n\n\u003cp align=\"center\"\u003e\u003ca href=\"https://solutionforest.com\" target=\"_blank\"\u003e\u003cimg src=\"https://github.com/solutionforest/.github/blob/main/docs/images/sf.png?raw=true\" width=\"150\"\u003e\u003c/a\u003e\u003c/p\u003e\n\n## About Solution Forest\n\n[Solution Forest](https://solutionforest.com) Web development agency based in Hong Kong. We help customers to solve their problems. We Love Open Sources.\n\nWe have built a collection of best-in-class products:\n\n-   [InspireCMS](https://inspirecms.net): A full-featured Laravel CMS with everything you need out of the box. Build smarter, ship faster with our complete content management solution.\n-   [Filaletter](https://filaletter.solutionforest.net): Filaletter - Filament Newsletter Plugin\n-   [Website CMS Management](https://filamentphp.com/plugins/solution-forest-cms-website): A hands-on Filament CMS plugin for those who prefer more manual control over their website content management.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsolutionforest%2Ffilament-translate-field","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsolutionforest%2Ffilament-translate-field","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsolutionforest%2Ffilament-translate-field/lists"}