Complete translation solution for Filament v4 that provides automatic translation for all components with zero configuration, plus a powerful translation management interface for development.
- π― Zero Configuration: Form fields, columns, actions work instantly
- π§ Simple Traits: Resources, Pages, Clusters need one line of code
- ποΈ Smart Fallbacks: Intelligent fallback strategies when translations are missing
- π± Translation Manager: Built-in interface to manage translations (development mode)
- π Multi-locale Support: Full Laravel translation system support
- π Status Dashboard: Visual overview of implementation status
- β‘ High Performance: Optimized with caching and lazy evaluation
composer require rodrigofs/filament-smart-translatephp artisan vendor:publish --tag=filament-smart-translate-configphp artisan filament-smart-translate:status// config/app.php
'locale' => 'pt_BR', // or your preferred locale// lang/pt_BR.json
{
"name": "Nome",
"email": "E-mail",
"user": "UsuΓ‘rio",
"admin": "AdministraΓ§Γ£o",
"create": "Criar",
"edit": "Editar",
"delete": "Excluir"
}Only for Resources, Pages, and Clusters - other components work automatically:
// Resources
use Rodrigofs\FilamentSmartTranslate\Traits\Resource\ResourceTranslateble;
class UserResource extends Resource
{
use ResourceTranslateble; // β Add this line
}
// Pages
use Rodrigofs\FilamentSmartTranslate\Traits\Page\PageTranslateble;
class Settings extends Page
{
use PageTranslateble; // β Add this line
}
// Clusters
use Rodrigofs\FilamentSmartTranslate\Traits\Cluster\ClusterTranslateble;
class UserManagement extends Cluster
{
use ClusterTranslateble; // β Add this line
}That's it! Your Filament interface will now display translated labels automatically.
These components work instantly with zero configuration:
- Form Fields: TextInput, Select, Checkbox, etc.
- Table Columns: TextColumn, BooleanColumn, etc.
- Actions: CreateAction, EditAction, DeleteAction, etc.
- Layout: Section, Tabs, Group, etc.
These components need one trait per class:
- Resources: Model labels & navigation β
ResourceTranslateble - Pages: Navigation groups β
PageTranslateble - Clusters: Breadcrumbs & navigation β
ClusterTranslateble
| Component | Automatic | Trait Required |
|---|---|---|
| Form Fields | β Yes | β No |
| Table Columns | β Yes | β No |
| Actions | β Yes | β No |
| Layout | β Yes | β No |
| Resources | β No | β Yes |
| Pages | β No | β Yes |
| Clusters | β No | β Yes |
The package includes a powerful translation management interface for development environments.
The Translation Manager should only be used in development environments to avoid Git conflicts during production deployments.
The Problem: The manager modifies JSON translation files directly. When you pull updates from Git to your production server, these local changes will conflict with incoming changes, potentially causing deployment failures or requiring manual conflict resolution during git pull operations.
use Filament\Pages\Page;use Rodrigofs\FilamentSmartTranslate\Traits\Page\PageTranslateble;
Add the TranslationPlugin to your Filament panel:
// app/Providers/Filament/AdminPanelProvider.php
use Rodrigofs\FilamentSmartTranslate\TranslationPlugin;
public function panel(Panel $panel): Panel
{
return $panel
// ... other configurations
->plugins([
TranslationPlugin::make(), // β Add this line
// ... other plugins
]);
}Add to your configuration:
// config/filament-smart-translate.php
'translation_page' => [
'enabled' => true,
'dev_only' => true, // β Important: Only in development
'navigation' => [
'enabled' => true,
'group' => 'Development',
'sort' => 99,
'icon' => 'heroicon-o-language',
],
'page' => [
'title' => 'Translation Manager',
'navigation_label' => 'Translations',
],
'features' => [
'export' => true,
'backup' => true,
'language_selector' => true,
'bulk_actions' => true,
],
'authorize' => env('APP_DEBUG', false), // Only when debug is enabled
],Translation Manager interface showing the translation editing capabilities
π Multi-language Interface
- Switch between locales instantly
- Add, edit, delete translations
- Bulk operations for efficiency
π Statistics Dashboard
- Total translations count
- Empty translations detection
- Progress tracking per locale
πΎ Backup & Export
- Automatic backups before changes
- Export translations to JSON
- Safe file handling
π Search Functionality
- Search translations by key or value
If you must use the Translation Manager in production:
- Remove translation files from Git tracking:
# Add to .gitignore
lang/*.json
!lang/en.json # Keep English as template- Configure for production:
'translation_page' => [
'enabled' => env('TRANSLATION_MANAGER_ENABLED', false),
'dev_only' => false,
'authorize' => function () {
return auth()->user()?->hasRole('admin');
},
],- Use environment variable:
# Only enable when needed
TRANSLATION_MANAGER_ENABLED=truegit pull operations).
When translations are missing, the package applies intelligent fallback strategies:
Keeps the original key format:
user_name β User name
email_address β Email address
Converts to human-readable format:
user_name β User Name
emailAddress β Email Address
Converts to lowercase with hyphens:
user_name β user-name
email_address β email-address
'components' => [
'fields' => [
'enabled' => true,
'fallback_strategy' => 'original'
],
'resources' => [
'enabled' => true,
'fallback_strategy' => 'humanize'
],
'actions' => [
'enabled' => true,
'fallback_strategy' => 'lower_case'
]
]Create your own fallback strategy:
<?php
namespace App\Strategies;
use Rodrigofs\FilamentSmartTranslate\Support\Fallback\FallbackStrategyInterface;
class UppercaseStrategy implements FallbackStrategyInterface
{
public function apply(string $key): string
{
return strtoupper(str_replace('_', ' ', $key));
}
}Register in configuration:
'fallback_strategies' => [
'uppercase' => \App\Strategies\UppercaseStrategy::class,
],{
"resources.user": "UsuΓ‘rio",
"navigations.admin": "AdministraΓ§Γ£o",
"actions.create": "Criar",
"fields.name": "Nome"
}{
"name": "Nome",
"email": "E-mail",
"user": "UsuΓ‘rio"
}- Component-prefixed key (
resources.user) - Direct key (
user) - Fallback strategy result
Get a complete overview of your setup:
php artisan filament-smart-translate:statusShows:
- β Package status (enabled/disabled)
- π― Trait usage (Resources, Pages, Clusters)
β οΈ Missing trait candidates- π§ Component coverage with strategies
- π Overall statistics and tips
Example output:
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Filament Smart Translation - Status Report β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
π¦ Package Status: β ENABLED
π― Trait Usage:
β ResourceTranslateble (2 files)
β Files that could use traits: 3 candidates
π§ Component Coverage:
β Resources (humanize)
β Fields (original)
β Actions (lower_case)
π Coverage Summary: 9/9 components active (100%)
<?php
namespace App\Filament\Resources;
use App\Models\User;
use Filament\Forms;
use Filament\Resources\Resource;
use Filament\Tables;
use Rodrigofs\FilamentSmartTranslate\Traits\Resource\ResourceTranslateble;
class UserResource extends Resource
{
use ResourceTranslateble; // β Add this for model labels
protected static ?string $model = User::class;
protected static ?string $navigationGroup = 'user_management';
public static function form(Form $form): Form
{
return $form->schema([
// These translate automatically (no code changes needed)
Forms\Components\TextInput::make('name'),
Forms\Components\TextInput::make('email'),
Forms\Components\Select::make('role'),
Forms\Components\Section::make('profile') // Section titles too!
->schema([
Forms\Components\TextInput::make('first_name'),
Forms\Components\TextInput::make('last_name'),
]),
]);
}
public static function table(Table $table): Table
{
return $table
->columns([
// Column headers automatically translated
Tables\Columns\TextColumn::make('name'),
Tables\Columns\TextColumn::make('email'),
Tables\Columns\TextColumn::make('role'),
])
->actions([
// Action labels automatically translated
Tables\Actions\EditAction::make(),
Tables\Actions\DeleteAction::make(),
]);
}
}// lang/pt_BR.json
{
"name": "Nome",
"email": "E-mail",
"role": "FunΓ§Γ£o",
"first_name": "Primeiro Nome",
"last_name": "Γltimo Nome",
"profile": "Perfil",
"resources.user": "UsuΓ‘rio",
"navigations.user_management": "Gerenciamento de UsuΓ‘rios",
"actions.edit": "Editar",
"actions.delete": "Excluir"
}Result: Complete Portuguese interface with intelligent fallbacks!
Full configuration options:
<?php
// config/filament-smart-translate.php
return [
// Global enable/disable
'enabled' => env('FILAMENT_SMART_TRANSLATE_ENABLED', true),
// Translation Manager (Development Feature)
'translation_page' => [
'enabled' => false, // Enable translation management interface
'dev_only' => true, // β οΈ Important: Only in development
'navigation' => [
'enabled' => true,
'group' => 'Development',
'sort' => 99,
'icon' => 'heroicon-o-language',
],
'page' => [
'title' => 'Translation Manager',
'navigation_label' => 'Translations',
],
'features' => [
'export' => true,
'backup' => true,
'language_selector' => true,
'bulk_actions' => true,
],
'authorize' => env('APP_DEBUG', false),
],
// Component-specific settings
'components' => [
'resources' => [
'enabled' => true,
'fallback_strategy' => 'original'
],
'fields' => [
'enabled' => true,
'fallback_strategy' => 'original'
],
'actions' => [
'enabled' => true,
'fallback_strategy' => 'original'
],
// ... other components
],
// Custom fallback strategies
'fallback_strategies' => [
// 'custom' => \App\Strategies\CustomStrategy::class,
],
// Debug settings
'debug' => [
'log_missing_translations' => env('FILAMENT_SMART_TRANSLATE_DEBUG', false),
],
];- Check locale: Verify
config/app.phplocale setting - Clear cache: Run
php artisan config:clear - Add traits: Resources/Pages/Clusters need traits
- Check files: Ensure translation files exist
- Run status: Use
php artisan filament-smart-translate:status
Add the required traits:
// Resource
use ResourceTranslateble;
// Page
use PageTranslateble;
// Cluster
use ClusterTranslateble;- Register the plugin: Add
TranslationPlugin::make()to your Filament panel - Enable in config: Set
translation_page.enabled => true - Check authorization: Verify
authorizecallback - Development mode: Ensure you're in development environment
- Clear cache: Run
php artisan config:clear
The Issue: Translation Manager changes create local modifications that conflict with git pull during production updates.
Recommended Solution: Use Translation Manager only in development.
Alternative for Production Use: Remove translation files from Git tracking:
echo "lang/*.json" >> .gitignore
git rm --cached lang/*.json- PHP: 8.2+
- Laravel: 11+
- Filament: 4.0+
- Fork the repository
- Create your feature branch
- Run tests:
composer test - Submit a pull request
MIT License - see LICENSE file.
- Filament Team: For the amazing admin framework
- Laravel Team: For the solid foundation
- Community: For feedback and contributions
Made with β€οΈ for the Filament community
