filament / spatie-laravel-translatable-plugin
Filament support for `spatie/laravel-translatable`.
Requires
- php: ^8.1
- filament/support: v3.2.121
- illuminate/support: ^10.45|^11.0
- spatie/laravel-translatable: ^6.0
- 3.x-dev
- v3.2.121
- v3.2.120
- v3.2.119
- v3.2.118
- v3.2.117
- v3.2.116
- v3.2.115
- v3.2.114
- v3.2.113
- v3.2.112
- v3.2.111
- v3.2.110
- v3.2.109
- v3.2.108
- v3.2.107
- v3.2.106
- v3.2.105
- v3.2.104
- v3.2.103
- v3.2.102
- v3.2.101
- v3.2.100
- v3.2.99
- v3.2.98
- v3.2.97
- v3.2.96
- v3.2.95
- v3.2.94
- v3.2.93
- v3.2.92
- v3.2.91
- v3.2.90
- v3.2.89
- v3.2.88
- v3.2.87
- v3.2.87-beta1
- v3.2.86
- v3.2.85
- v3.2.84
- v3.2.83
- v3.2.82
- v3.2.81
- v3.2.80
- v3.2.79
- v3.2.78
- v3.2.77
- v3.2.76
- v3.2.75
- v3.2.74
- v3.2.73
- v3.2.72
- v3.2.71
- v3.2.70
- v3.2.69
- v3.2.68
- v3.2.67
- v3.2.66
- v3.2.65
- v3.2.64
- v3.2.63
- v3.2.62
- v3.2.61
- v3.2.60
- v3.2.59
- v3.2.58
- v3.2.57
- v3.2.56
- v3.2.55
- v3.2.54
- v3.2.53
- v3.2.52
- v3.2.51
- v3.2.50
- v3.2.49
- v3.2.48
- v3.2.47
- v3.2.46
- v3.2.45
- v3.2.44
- v3.2.43
- v3.2.42
- v3.2.41
- v3.2.40
- v3.2.39
- v3.2.38
- v3.2.37
- v3.2.36
- v3.2.35
- v3.2.34
- v3.2.33
- v3.2.32
- v3.2.31
- v3.2.30
- v3.2.29
- v3.2.28
- v3.2.27
- v3.2.26
- v3.2.25
- v3.2.25-beta1
- v3.2.24
- v3.2.23
- v3.2.22
- v3.2.21
- v3.2.20
- v3.2.19
- v3.2.18
- v3.2.17
- v3.2.16
- v3.2.15
- v3.2.14
- v3.2.13
- v3.2.12
- v3.2.11
- v3.2.10
- v3.2.9
- v3.2.8
- v3.2.7
- v3.2.6
- v3.2.5
- v3.2.4
- v3.2.3
- v3.2.2
- v3.2.1
- v3.2.0
- v3.1.47
- v3.1.46
- v3.1.45
- v3.1.44
- v3.1.43
- v3.1.42
- v3.1.41
- v3.1.40
- v3.1.39
- v3.1.38
- v3.1.37
- v3.1.36
- v3.1.35
- v3.1.34
- v3.1.33
- v3.1.32
- v3.1.31
- v3.1.30
- v3.1.29
- v3.1.28
- v3.1.27
- v3.1.26
- v3.1.25
- v3.1.24
- v3.1.23
- v3.1.22
- v3.1.21
- v3.1.20
- v3.1.19
- v3.1.18
- v3.1.17
- v3.1.16
- v3.1.15
- v3.1.14
- v3.1.13
- v3.1.12
- v3.1.11
- v3.1.10
- v3.1.9
- v3.1.8
- v3.1.7
- v3.1.6
- v3.1.5
- v3.1.4
- v3.1.3
- v3.1.2
- v3.1.1
- v3.1.0
- v3.1.0-alpha4
- v3.1.0-alpha3
- v3.1.0-alpha2
- v3.1.0-alpha1
- v3.0.103
- v3.0.102
- v3.0.101
- v3.0.100
- v3.0.99
- v3.0.98
- v3.0.97
- v3.0.96
- v3.0.95
- v3.0.94
- v3.0.93
- v3.0.92
- v3.0.91
- v3.0.90
- v3.0.89
- v3.0.88
- v3.0.87
- v3.0.86
- v3.0.85
- v3.0.84
- v3.0.83
- v3.0.82
- v3.0.81
- v3.0.80
- v3.0.79
- v3.0.78
- v3.0.77
- v3.0.76
- v3.0.75
- v3.0.74
- v3.0.73
- v3.0.72
- v3.0.71
- v3.0.70
- v3.0.69
- v3.0.68
- v3.0.67
- v3.0.66
- v3.0.65
- v3.0.64
- v3.0.63
- v3.0.62
- v3.0.61
- v3.0.60
- v3.0.59
- v3.0.58
- v3.0.57
- v3.0.56
- v3.0.55
- v3.0.54
- v3.0.53
- v3.0.52
- v3.0.51
- v3.0.50
- v3.0.49
- v3.0.48
- v3.0.47
- v3.0.46
- v3.0.45
- v3.0.44
- v3.0.43
- v3.0.42
- v3.0.41
- v3.0.40
- v3.0.39
- v3.0.38
- v3.0.37
- v3.0.36
- v3.0.35
- v3.0.34
- v3.0.33
- v3.0.32
- v3.0.31
- v3.0.30
- v3.0.29
- v3.0.28
- v3.0.27
- v3.0.26
- v3.0.25
- v3.0.24
- v3.0.23
- v3.0.22
- v3.0.21
- v3.0.20
- v3.0.19
- v3.0.18
- v3.0.17
- v3.0.16
- v3.0.15
- v3.0.14
- v3.0.13
- v3.0.12
- v3.0.11
- v3.0.10
- v3.0.9
- v3.0.8
- v3.0.7
- v3.0.6
- v3.0.5
- v3.0.4
- v3.0.3
- v3.0.2
- v3.0.1
- v3.0.0
- v3.0.0-beta28
- v3.0.0-beta27
- v3.0.0-beta26
- v3.0.0-beta25
- v3.0.0-beta24
- v3.0.0-beta23
- v3.0.0-beta22
- v3.0.0-beta21
- v3.0.0-beta20
- v3.0.0-beta19
- v3.0.0-beta18
- v3.0.0-beta17
- v3.0.0-beta16
- v3.0.0-beta15
- v3.0.0-beta14
- v3.0.0-beta13
- v3.0.0-beta12
- v3.0.0-beta11
- v3.0.0-beta10
- v3.0.0-beta9
- v3.0.0-beta8
- v3.0.0-beta7
- v3.0.0-beta6
- v3.0.0-beta5
- v3.0.0-beta4
- v3.0.0-beta3
- v3.0.0-beta2
- v3.0.0-beta1
- v3.0.0-alpha137
- v3.0.0-alpha136
- v3.0.0-alpha135
- v3.0.0-alpha132
- v3.0.0-alpha131
- v3.0.0-alpha130
- v3.0.0-alpha129
- v3.0.0-alpha128
- v3.0.0-alpha127
- v3.0.0-alpha126
- v3.0.0-alpha125
- v3.0.0-alpha124
- v3.0.0-alpha123
- v3.0.0-alpha122
- v3.0.0-alpha121
- v3.0.0-alpha120
- v3.0.0-alpha119
- v3.0.0-alpha118
- v3.0.0-alpha117
- v3.0.0-alpha116
- v3.0.0-alpha115
- v3.0.0-alpha114
- v3.0.0-alpha113
- v3.0.0-alpha112
- v3.0.0-alpha111
- v3.0.0-alpha110
- v3.0.0-alpha109
- v3.0.0-alpha108
- v3.0.0-alpha107
- v3.0.0-alpha106
- v3.0.0-alpha105
- v3.0.0-alpha104
- v3.0.0-alpha103
- v3.0.0-alpha102
- v3.0.0-alpha101
- v3.0.0-alpha100
- v3.0.0-alpha99
- v3.0.0-alpha98
- v3.0.0-alpha97
- v3.0.0-alpha96
- v3.0.0-alpha95
- v3.0.0-alpha94
- v3.0.0-alpha93
- v3.0.0-alpha92
- v3.0.0-alpha91
- v3.0.0-alpha90
- v3.0.0-alpha89
- v3.0.0-alpha88
- v3.0.0-alpha87
- v3.0.0-alpha86
- v3.0.0-alpha85
- v3.0.0-alpha84
- v3.0.0-alpha83
- v3.0.0-alpha82
- v3.0.0-alpha81
- v3.0.0-alpha80
- v3.0.0-alpha79
- v3.0.0-alpha78
- v3.0.0-alpha77
- v3.0.0-alpha76
- v3.0.0-alpha75
- v3.0.0-alpha74
- v3.0.0-alpha73
- v3.0.0-alpha72
- v3.0.0-alpha71
- v3.0.0-alpha70
- v3.0.0-alpha69
- v3.0.0-alpha68
- v3.0.0-alpha67
- v3.0.0-alpha66
- v3.0.0-alpha65
- v3.0.0-alpha64
- v3.0.0-alpha63
- v3.0.0-alpha62
- v3.0.0-alpha61
- v3.0.0-alpha60
- v3.0.0-alpha59
- v3.0.0-alpha58
- v3.0.0-alpha57
- v3.0.0-alpha56
- v3.0.0-alpha55
- v3.0.0-alpha54
- v3.0.0-alpha53
- v3.0.0-alpha52
- v3.0.0-alpha51
- v3.0.0-alpha50
- v3.0.0-alpha49
- v3.0.0-alpha48
- v3.0.0-alpha47
- v3.0.0-alpha46
- v3.0.0-alpha45
- v3.0.0-alpha44
- v3.0.0-alpha43
- v3.0.0-alpha42
- v3.0.0-alpha41
- v3.0.0-alpha40
- v3.0.0-alpha39
- v3.0.0-alpha38
- v3.0.0-alpha37
- v3.0.0-alpha36
- v3.0.0-alpha35
- v3.0.0-alpha34
- v3.0.0-alpha33
- v3.0.0-alpha32
- v3.0.0-alpha31
- v3.0.0-alpha30
- v3.0.0-alpha29
- v3.0.0-alpha28
- v3.0.0-alpha27
- v3.0.0-alpha26
- v3.0.0-alpha25
- v3.0.0-alpha24
- v3.0.0-alpha23
- v3.0.0-alpha10
- v3.0.0-alpha9
- v3.0.0-alpha8
- v3.0.0-alpha7
- v3.0.0-alpha6
- v3.0.0-alpha5
- v3.0.0-alpha4
- v3.0.0-alpha3
- v3.0.0-alpha2
- v3.0.0-alpha1
- 2.x-dev
- v2.17.56
- v2.17.55
- v2.17.54
- v2.17.53
- v2.17.52
- v2.17.51
- v2.17.50
- v2.17.49
- v2.17.48
- v2.17.47
- v2.17.46
- v2.17.45
- v2.17.44
- v2.17.43
- v2.17.42
- v2.17.41
- v2.17.40
- v2.17.39
- v2.17.38
- v2.17.37
- v2.17.36
- v2.17.35
- v2.17.34
- v2.17.32
- v2.17.31
- v2.17.30
- v2.17.29
- v2.17.28
- v2.17.27
- v2.17.26
- v2.17.25
- v2.17.24
- v2.17.23
- v2.17.22
- v2.17.21
- v2.17.20
- v2.17.19
- v2.17.18
- v2.17.17
- v2.17.16
- v2.17.15
- v2.17.14
- v2.17.13
- v2.17.12
- v2.17.11
- v2.17.10
- v2.17.9
- v2.17.8
- v2.17.7
- v2.17.6
- v2.17.5
- v2.17.4
- v2.17.3
- v2.17.2
- v2.17.1
- v2.17.0
- v2.16.70
- v2.16.69
- v2.16.68
- v2.16.67
- v2.16.66
- v2.16.65
- v2.16.64
- v2.16.63
- v2.16.62
- v2.16.61
- v2.16.60
- v2.16.59
- v2.16.58
- v2.16.57
- v2.16.56
- v2.16.55
- v2.16.54
- v2.16.53
- v2.16.52
- v2.16.51
- v2.16.50
- v2.16.49
- v2.16.48
- v2.16.47
- v2.16.46
- v2.16.45
- v2.16.44
- v2.16.43
- v2.16.42
- v2.16.41
- v2.16.40
- v2.16.39
- v2.16.38
- v2.16.37
- v2.16.36
- v2.16.35
- v2.16.34
- v2.16.33
- v2.16.32
- v2.16.31
- v2.16.29
- v2.16.28
- v2.16.27
- v2.16.26
- v2.16.25
- v2.16.24
- v2.16.23
- v2.16.22
- v2.16.21
- v2.16.20
- v2.16.19
- v2.16.18
- v2.16.17
- v2.16.16
- v2.16.15
- v2.16.14
- v2.16.13
- v2.16.12
- v2.16.11
- v2.16.10
- v2.16.9
- v2.16.8
- v2.16.7
- v2.16.6
- v2.16.5
- v2.16.4
- v2.16.3
- v2.16.2
- v2.16.1
- v2.16.0
- v2.15.49
- v2.15.48
- v2.15.47
- v2.15.46
- v2.15.45
- v2.15.44
- v2.15.43
- v2.15.42
- v2.15.41
- v2.15.40
- v2.15.39
- v2.15.38
- v2.15.37
- v2.15.36
- v2.15.35
- v2.15.34
- v2.15.33
- v2.15.32
- v2.15.31
- v2.15.30
- v2.15.29
- v2.15.28
- v2.15.27
- v2.15.26
- v2.15.25
- v2.15.24
- v2.15.23
- v2.15.22
- v2.15.21
- v2.15.20
- v2.15.19
- v2.15.19-beta1
- v2.15.18
- v2.15.17
- v2.15.16
- v2.15.15
- v2.15.14
- v2.15.13
- v2.15.12
- v2.15.11
- v2.15.10
- v2.15.9
- v2.15.8
- v2.15.7
- v2.15.6
- v2.15.5
- v2.15.4
- v2.15.3
- v2.15.2
- v2.15.1
- v2.15.0
- v2.14.5
- v2.14.4
- v2.14.3
- v2.14.2
- v2.14.1
- v2.14.0
- v2.13.28
- v2.13.27
- v2.13.26
- v2.13.25
- v2.13.24
- v2.13.23
- v2.13.22
- v2.13.21
- v2.13.20
- v2.13.19
- v2.13.18
- v2.13.17
- v2.13.16
- v2.13.15
- v2.13.14
- v2.13.13
- v2.13.12
- v2.13.11
- v2.13.10
- v2.13.9
- v2.13.8
- v2.13.7
- v2.13.6
- v2.13.5
- v2.13.4
- v2.13.3
- v2.13.2
- v2.13.1
- v2.13.0
- v2.13.0-beta1
- v2.12.31
- v2.12.30
- v2.12.29
- v2.12.28
- v2.12.27
- v2.12.26
- v2.12.25
- v2.12.24
- v2.12.23
- v2.12.22
- v2.12.21
- v2.12.20
- v2.12.19
- v2.12.18
- v2.12.17
- v2.12.16
- v2.12.15
- v2.12.14
- v2.12.13
- v2.12.12
- v2.12.11
- v2.12.10
- v2.12.9
- v2.12.8
- v2.12.7
- v2.12.6
- v2.12.5
- v2.12.4
- v2.12.3
- v2.12.2
- v2.12.1
- v2.12.0
- v2.12.0-beta8
- v2.12.0-beta7
- v2.12.0-beta6
- v2.12.0-beta5
- v2.12.0-beta4
- v2.12.0-beta3
- v2.12.0-beta2
- v2.12.0-beta1
- v2.11.12
- v2.11.11
- v2.11.10
- v2.11.9
- v2.11.8
- v2.11.7
- v2.11.6
- v2.11.5
- v2.11.4
- v2.11.3
- v2.11.2
- v2.11.1
- v2.11.0
- v2.10.46
- v2.10.45
- v2.10.44
- v2.10.43
- v2.10.42
- v2.10.41
- v2.10.40
- v2.10.39
- v2.10.38
- v2.10.37
- v2.10.36
- v2.10.35
- v2.10.34
- v2.10.33
- v2.10.32
- v2.10.31
- v2.10.30
- v2.10.29
- v2.10.28
- v2.10.27
- v2.10.26
- v2.10.25
- v2.10.24
- v2.10.23
- v2.10.22
- v2.10.21
- v2.10.20
- v2.10.19
- v2.10.18
- v2.10.17
- v2.10.16
- v2.10.15
- v2.10.14
- v2.10.13
- v2.10.12
- v2.10.11
- v2.10.10
- v2.10.9
- v2.10.8
- v2.10.7
- v2.10.6
- v2.10.5
- v2.10.4
- v2.10.3
- v2.10.2
- v2.10.1
- v2.10.0
- v2.10.0-beta1
- v2.9.19
- v2.9.18
- v2.9.17
- v2.9.16
- v2.9.15
- v2.9.14
- v2.9.13
- v2.9.12
- v2.9.11
- v2.9.10
- v2.9.9
- v2.9.8
- v2.9.7
- v2.9.6
- v2.9.5
- v2.9.4
- v2.9.3
- v2.9.2
- v2.9.1
- v2.9.0
- v2.8.11
- v2.8.10
- v2.8.9
- v2.8.8
- v2.8.7
- v2.8.6
- v2.8.5
- v2.8.4
- v2.8.3
- v2.8.2
- v2.8.1
- v2.8.0
- v2.7.17
- v2.7.16
- v2.7.15
- v2.7.14
- v2.7.13
- v2.7.12
- v2.7.11
- v2.7.10
- v2.7.9
- v2.7.8
- v2.7.7
- v2.7.6
- v2.7.5
- v2.7.4
- v2.7.1
- v2.7.0
- v2.6.6
- v2.6.5
- v2.6.4
- v2.6.3
- v2.6.2
- v2.6.1
- v2.6.0
- v2.5.31
- v2.5.30
- v2.5.29
- v2.5.28
- v2.5.27
- v2.5.26
- v2.5.25
- v2.5.24
- v2.5.23
- v2.5.22
- v2.5.21
- v2.5.20
- v2.5.19
- v2.5.18
- v2.5.17
- v2.5.16
- v2.5.15
- v2.5.14
- v2.5.13
- v2.5.12
- v2.5.11
- v2.5.10
- v2.5.9
- v2.5.8
- v2.5.7
- v2.5.6
- v2.5.5
- v2.5.4
- v2.5.3
- v2.5.2
- v2.5.1
- v2.5.0
- v2.4.58
- v2.4.57
- v2.4.56
- v2.4.55
- v2.4.54
- v2.4.53
- v2.4.52
- v2.4.51
- v2.4.50
- dev-3.x-alpha
This package is auto-updated.
Last update: 2024-10-24 13:47:35 UTC
README
Installation
Install the plugin with Composer:
composer require filament/spatie-laravel-translatable-plugin:"^3.2" -W
Adding the plugin to a panel
To add a plugin to a panel, you must include it in the configuration file using the plugin()
method:
use Filament\SpatieLaravelTranslatablePlugin; public function panel(Panel $panel): Panel { return $panel // ... ->plugin(SpatieLaravelTranslatablePlugin::make()); }
Setting the default translatable locales
To set up the locales that can be used to translate content, you can pass an array of locales to the defaultLocales()
plugin method:
use Filament\SpatieLaravelTranslatablePlugin; public function panel(Panel $panel): Panel { return $panel // ... ->plugin( SpatieLaravelTranslatablePlugin::make() ->defaultLocales(['en', 'es']), ); }
Preparing your model class
You need to make your model translatable. You can read how to do this in Spatie's documentation.
Preparing your resource class
You must apply the Filament\Resources\Concerns\Translatable
trait to your resource class:
use Filament\Resources\Concerns\Translatable; use Filament\Resources\Resource; class BlogPostResource extends Resource { use Translatable; // ... }
Making resource pages translatable
After 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:
use Filament\Actions; use Filament\Resources\Pages\ListRecords; class ListBlogPosts extends ListRecords { use ListRecords\Concerns\Translatable; protected function getHeaderActions(): array { return [ Actions\LocaleSwitcher::make(), // ... ]; } // ... }
use Filament\Actions; use Filament\Resources\Pages\CreateRecord; class CreateBlogPost extends CreateRecord { use CreateRecord\Concerns\Translatable; protected function getHeaderActions(): array { return [ Actions\LocaleSwitcher::make(), // ... ]; } // ... }
use Filament\Actions; use Filament\Resources\Pages\EditRecord; class EditBlogPost extends EditRecord { use EditRecord\Concerns\Translatable; protected function getHeaderActions(): array { return [ Actions\LocaleSwitcher::make(), // ... ]; } // ... }
And if you have a ViewRecord
page for your resource:
use Filament\Actions; use Filament\Resources\Pages\ViewRecord; class ViewBlogPost extends ViewRecord { use ViewRecord\Concerns\Translatable; protected function getHeaderActions(): array { return [ Actions\LocaleSwitcher::make(), // ... ]; } // ... }
If you're using a simple resource, you can make the ManageRecords
page translatable instead:
use Filament\Actions; use Filament\Resources\Pages\ManageRecords; class ManageBlogPosts extends ListRecords { use ManageRecords\Concerns\Translatable; protected function getHeaderActions(): array { return [ Actions\LocaleSwitcher::make(), // ... ]; } // ... }
Setting the translatable locales for a particular resource
By default, the translatable locales can be set globally for all resources in the plugin configuration. Alternatively, you can customize the translatable locales for a particular resource by overriding the getTranslatableLocales()
method in your resource class:
use Filament\Resources\Concerns\Translatable; use Filament\Resources\Resource; class BlogPostResource extends Resource { use Translatable; // ... public static function getTranslatableLocales(): array { return ['en', 'fr']; } }
Translating relation managers
First, you must apply the Filament\Resources\RelationManagers\Concerns\Translatable
trait to the relation manager class:
use Filament\Resources\RelationManagers\Concerns\Translatable; use Filament\Resources\RelationManagers\RelationManager; class BlogPostsRelationManager extends RelationManager { use Translatable; // ... }
Now, you can add a new LocaleSwitcher
action to the header of the relation manager's table()
:
use Filament\Tables; use Filament\Tables\Table; public function table(Table $table): Table { return $table ->columns([ // ... ]) ->headerActions([ // ... Tables\Actions\LocaleSwitcher::make(), ]); }
Inheriting the relation manager's active locale from the resource page
If 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:
use Filament\Resources\RelationManagers\Concerns\Translatable; use Filament\Resources\RelationManagers\RelationManager; use Livewire\Attributes\Reactive; class BlogPostsRelationManager extends RelationManager { use Translatable; #[Reactive] public ?string $activeLocale = null; // ... }
If you do this, you no longer need a LocaleSwitcher
action in the table()
.
Setting the translatable locales for a particular relation manager
By default, the translatable locales can be set globally for all relation managers in the plugin configuration. Alternatively, you can customize the translatable locales for a particular relation manager by overriding the getTranslatableLocales()
method in your relation manager class:
use Filament\Resources\RelationManagers\Concerns\Translatable; use Filament\Resources\RelationManagers\RelationManager; class BlogPostsRelationManager extends RelationManager { use Translatable; // ... public function getTranslatableLocales(): array { return ['en', 'fr']; } }
Publishing translations
If you wish to translate the package, you may publish the language files using:
php artisan vendor:publish --tag=filament-spatie-laravel-translatable-plugin-translations