{"id":18301959,"url":"https://github.com/filamentphp/spatie-laravel-translatable-plugin","last_synced_at":"2025-05-16T05:06:31.503Z","repository":{"id":38441476,"uuid":"432542325","full_name":"filamentphp/spatie-laravel-translatable-plugin","owner":"filamentphp","description":"[READ ONLY] Subtree split of the Filament spatie/laravel-translatable Plugin (see filamentphp/filament)","archived":false,"fork":false,"pushed_at":"2025-04-30T09:16:52.000Z","size":150,"stargazers_count":88,"open_issues_count":0,"forks_count":35,"subscribers_count":6,"default_branch":"3.x","last_synced_at":"2025-05-09T10:11:26.106Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://github.com/filamentphp/filament","language":"PHP","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/filamentphp.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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}},"created_at":"2021-11-27T18:55:22.000Z","updated_at":"2025-03-24T00:40:50.000Z","dependencies_parsed_at":"2022-08-09T04:16:29.748Z","dependency_job_id":"0bf19368-a5f0-46f4-9273-15cf1ffdf996","html_url":"https://github.com/filamentphp/spatie-laravel-translatable-plugin","commit_stats":{"total_commits":64,"total_committers":2,"mean_commits":32.0,"dds":0.03125,"last_synced_commit":"df2152448f65687696a3f37f8b3c2005e8692efe"},"previous_names":[],"tags_count":875,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/filamentphp%2Fspatie-laravel-translatable-plugin","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/filamentphp%2Fspatie-laravel-translatable-plugin/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/filamentphp%2Fspatie-laravel-translatable-plugin/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/filamentphp%2Fspatie-laravel-translatable-plugin/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/filamentphp","download_url":"https://codeload.github.com/filamentphp/spatie-laravel-translatable-plugin/tar.gz/refs/heads/3.x","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254471061,"owners_count":22076585,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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-11-05T15:17:32.558Z","updated_at":"2025-05-16T05:06:31.482Z","avatar_url":"https://github.com/filamentphp.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Filament Spatie Translatable Plugin\n\n## Installation\n\nInstall the plugin with Composer:\n\n```bash\ncomposer require filament/spatie-laravel-translatable-plugin:\"^3.2\" -W\n```\n\n## Adding the plugin to a panel\n\nTo add a plugin to a panel, you must include it in the configuration file using the `plugin()` method:\n\n```php\nuse Filament\\SpatieLaravelTranslatablePlugin;\n\npublic function panel(Panel $panel): Panel\n{\n    return $panel\n        // ...\n        -\u003eplugin(SpatieLaravelTranslatablePlugin::make());\n}\n```\n\n## Setting the default translatable locales\n\nTo set up the locales that can be used to translate content, you can pass an array of locales to the `defaultLocales()` plugin method:\n\n```php\nuse Filament\\SpatieLaravelTranslatablePlugin;\n\npublic function panel(Panel $panel): Panel\n{\n    return $panel\n        // ...\n        -\u003eplugin(\n            SpatieLaravelTranslatablePlugin::make()\n                -\u003edefaultLocales(['en', 'es']),\n        );\n}\n```\n\n## Preparing your model class\n\nYou need to make your model translatable. You can read how to do this in [Spatie's documentation](https://spatie.be/docs/laravel-translatable/installation-setup#content-making-a-model-translatable).\n\n## Preparing your resource class\n\nYou must apply the `Filament\\Resources\\Concerns\\Translatable` trait to your resource class:\n\n```php\nuse Filament\\Resources\\Concerns\\Translatable;\nuse Filament\\Resources\\Resource;\n\nclass BlogPostResource extends Resource\n{\n    use Translatable;\n    \n    // ...\n}\n```\n\n## Making resource pages translatable\n\nAfter [preparing your resource class](#preparing-your-resource-class), you must make each of your resource's pages translatable too. You can find your resource's pages in the `Pages` directory of each resource folder. To prepare a page, you must apply the corresponding `Translatable` trait to it, and install a `LocaleSwitcher` header action:\n\n```php\nuse Filament\\Actions;\nuse Filament\\Resources\\Pages\\ListRecords;\n\nclass ListBlogPosts extends ListRecords\n{\n    use ListRecords\\Concerns\\Translatable;\n    \n    protected function getHeaderActions(): array\n    {\n        return [\n            Actions\\LocaleSwitcher::make(),\n            // ...\n        ];\n    }\n    \n    // ...\n}\n```\n\n```php\nuse Filament\\Actions;\nuse Filament\\Resources\\Pages\\CreateRecord;\n\nclass CreateBlogPost extends CreateRecord\n{\n    use CreateRecord\\Concerns\\Translatable;\n    \n    protected function getHeaderActions(): array\n    {\n        return [\n            Actions\\LocaleSwitcher::make(),\n            // ...\n        ];\n    }\n    \n    // ...\n}\n```\n\n```php\nuse Filament\\Actions;\nuse Filament\\Resources\\Pages\\EditRecord;\n\nclass EditBlogPost extends EditRecord\n{\n    use EditRecord\\Concerns\\Translatable;\n    \n    protected function getHeaderActions(): array\n    {\n        return [\n            Actions\\LocaleSwitcher::make(),\n            // ...\n        ];\n    }\n    \n    // ...\n}\n```\n\nAnd if you have a `ViewRecord` page for your resource:\n\n```php\nuse Filament\\Actions;\nuse Filament\\Resources\\Pages\\ViewRecord;\n\nclass ViewBlogPost extends ViewRecord\n{\n    use ViewRecord\\Concerns\\Translatable;\n    \n    protected function getHeaderActions(): array\n    {\n        return [\n            Actions\\LocaleSwitcher::make(),\n            // ...\n        ];\n    }\n    \n    // ...\n}\n```\n\nIf you're using a simple resource, you can make the `ManageRecords` page translatable instead:\n\n```php\nuse Filament\\Actions;\nuse Filament\\Resources\\Pages\\ManageRecords;\n\nclass ManageBlogPosts extends ListRecords\n{\n    use ManageRecords\\Concerns\\Translatable;\n    \n    protected function getHeaderActions(): array\n    {\n        return [\n            Actions\\LocaleSwitcher::make(),\n            // ...\n        ];\n    }\n    \n    // ...\n}\n```\n\n### Setting the translatable locales for a particular resource\n\nBy default, the translatable locales can be [set globally for all resources in the plugin configuration](#setting-the-default-translatable-locales). Alternatively, you can customize the translatable locales for a particular resource by overriding the `getTranslatableLocales()` method in your resource class:\n\n```php\nuse Filament\\Resources\\Concerns\\Translatable;\nuse Filament\\Resources\\Resource;\n\nclass BlogPostResource extends Resource\n{\n    use Translatable;\n    \n    // ...\n    \n    public static function getTranslatableLocales(): array\n    {\n        return ['en', 'fr'];\n    }\n}\n```\n\n## Translating relation managers\n\nFirst, you must apply the `Filament\\Resources\\RelationManagers\\Concerns\\Translatable` trait to the relation manager class:\n\n```php\nuse Filament\\Resources\\RelationManagers\\Concerns\\Translatable;\nuse Filament\\Resources\\RelationManagers\\RelationManager;\n\nclass BlogPostsRelationManager extends RelationManager\n{\n    use Translatable;\n    \n    // ...\n}\n```\n\nNow, you can add a new `LocaleSwitcher` action to the header of the relation manager's `table()`:\n\n```php\nuse Filament\\Tables;\nuse Filament\\Tables\\Table;\n\npublic function table(Table $table): Table\n{\n    return $table\n        -\u003ecolumns([\n            // ...\n        ])\n        -\u003eheaderActions([\n            // ...\n            Tables\\Actions\\LocaleSwitcher::make(),\n        ]);\n}\n```\n\n### Inheriting the relation manager's active locale from the resource page\n\nIf you wish to reactively inherit the locale of the `Translatable` resource page that the relation manager is being displayed on, you can override the `$activeLocale` property and add Livewire's `Reactive` attribute to it:\n\n```php\nuse Filament\\Resources\\RelationManagers\\Concerns\\Translatable;\nuse Filament\\Resources\\RelationManagers\\RelationManager;\nuse Livewire\\Attributes\\Reactive;\n\nclass BlogPostsRelationManager extends RelationManager\n{\n    use Translatable;\n    \n    #[Reactive]\n    public ?string $activeLocale = null;\n    \n    // ...\n}\n```\n\nIf you do this, you no longer need a `LocaleSwitcher` action in the `table()`.\n\n### Setting the translatable locales for a particular relation manager\n\nBy default, the translatable locales can be [set globally for all relation managers in the plugin configuration](#setting-the-default-translatable-locales). Alternatively, you can customize the translatable locales for a particular relation manager by overriding the `getTranslatableLocales()` method in your relation manager class:\n\n```php\nuse Filament\\Resources\\RelationManagers\\Concerns\\Translatable;\nuse Filament\\Resources\\RelationManagers\\RelationManager;\n\nclass BlogPostsRelationManager extends RelationManager\n{\n    use Translatable;\n    \n    // ...\n    \n    public function getTranslatableLocales(): array\n    {\n        return ['en', 'fr'];\n    }\n}\n```\n\n## Publishing translations\n\nIf you wish to translate the package, you may publish the language files using:\n\n```bash\nphp artisan vendor:publish --tag=filament-spatie-laravel-translatable-plugin-translations\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffilamentphp%2Fspatie-laravel-translatable-plugin","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffilamentphp%2Fspatie-laravel-translatable-plugin","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffilamentphp%2Fspatie-laravel-translatable-plugin/lists"}