Getting started

This guide assumes that you've already set up your model to be translatable as per Spatie's documentation.

Preparing your resource class

First, you must apply the Filament\Resources\Concerns\Translatable trait to your resource class. This adds a getTranslatableLocales() method, which you may override to return an array of locales that the resource can be translated into:

use Filament\Resources\Concerns\Translatable;
use Filament\Resources\Resource;
 
class BlogPostResource extends Resource
{
use Translatable;
 
// ...
 
public static function getTranslatableLocales(): array
{
return ['en', 'es'];
}
}

You may publish the package's configuration file to set the default_locales for all resources at once.

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:

use Filament\Pages\Actions;
use Filament\Resources\Pages\ListRecords;
 
class ListBlogPosts extends ListRecords
{
use ListRecords\Concerns\Translatable;
 
protected function getActions(): array
{
return [
Actions\LocaleSwitcher::make(),
// ...
];
}
 
// ...
}
use Filament\Pages\Actions;
use Filament\Resources\Pages\CreateRecord;
 
class CreateBlogPost extends CreateRecord
{
use CreateRecord\Concerns\Translatable;
 
protected function getActions(): array
{
return [
Actions\LocaleSwitcher::make(),
// ...
];
}
 
// ...
}
use Filament\Pages\Actions;
use Filament\Resources\Pages\EditRecord;
 
class EditBlogPost extends EditRecord
{
use EditRecord\Concerns\Translatable;
 
protected function getActions(): array
{
return [
Actions\LocaleSwitcher::make(),
// ...
];
}
 
// ...
}

And if you have a ViewRecord page for your resource:

use Filament\Pages\Actions;
use Filament\Resources\Pages\ViewRecord;
 
class ViewBlogPost extends ViewRecord
{
use ViewRecord\Concerns\Translatable;
 
protected function getActions(): array
{
return [
Actions\LocaleSwitcher::make(),
// ...
];
}
 
// ...
}
Edit on GitHub

Still need help? Join our Discord community or open a GitHub discussion

Enjoying Filament?

We are open source at heart. To allow us to build new features, fix bugs, and run the community, we require your financial support.

Sponsor Filament on GitHub