syriable/filament-translator
Convention-based automatic translations for Filament panels. Derives translation keys from class and component names to keep UI code free of hard-coded labels. Covers forms, tables, actions, resources/pages/widgets, importers/exporters, with aliases, macros, and dev-time key scaffolding.
composer require syriable/filament-translator
public function panel(Panel $panel): Panel
{
return $panel->plugins([
TranslatorPlugin::make(),
]);
}
Translate a Filament form action label without hardcoding strings:
use Filament\Forms\Components\SubmitAction;
SubmitAction::make('submit')
->label(); // Automatically resolves to `livewire.{form}.actions.submit.label`
The package will generate the missing translation key in your lang/{locale}/livewire/{form}.php file during development if createMissingTranslationKeys() is enabled.
TextInput, Select, Actions).App\Filament\Resources\PostResource\Pages\CreatePost → filament.resources.post.pages.createApp\Filament\Resources\PostResource\Pages\EditPost\Actions\DeletePost → filament.resources.post.pages.edit.actions.delete__() helper or Filament’s built-in translation system.use Filament\Forms\Components\TextInput;
TextInput::make('name')
->label(); // Resolves to `filament.forms.components.name.label`
use Filament\Tables\Columns\TextColumn;
TextColumn::make('title')
->label(); // Resolves to `filament.tables.columns.title.label`
use Filament\Tables\Actions\Action;
Action::make('view')
->label(); // Resolves to `filament.tables.actions.view.label`
Map non-standard namespaces (e.g., Livewire) to lang paths:
TranslatorPlugin::make()
->pathAliases([
'App\\Livewire' => 'livewire',
]);
Now, App\Livewire\Auth\Login resolves to livewire.auth.login.
Extend provided base classes to enforce translation conventions:
use Syriable\Filament\Pages\TranslatablePage;
class CreatePost extends TranslatablePage
{
// All labels will auto-resolve from conventions
}
Enable scaffolding of missing translation keys:
TranslatorPlugin::make()
->createMissingTranslationKeys();
This generates stubs like:
// lang/en/livewire/auth/login.php
return [
'form' => [
'components' => [
'actions' => [
'forgot-password' => [
'label' => 'Forgot Password',
],
],
],
],
];
Double Booting:
registerDefaults() if TranslatorPlugin is already registered on the panel.Path Aliases in Guest Routes:
/login) require manual booting:
app(ConventionRegistry::class)->registerDefaults();
TranslatorPlugin is registered on the default panel if guest routes need custom aliases.Hint Icon Tooltips:
hintIcon() may not work in older Filament versions (pre-4.x without func_num_args() guard).TextInput::make('password')
->hintIcon('heroicon-o-question-mark-circle');
If the tooltip disappears, upgrade Filament or use the two-argument form:
->hintIcon('heroicon-o-question-mark-circle', 'Custom tooltip');
Required Attributes:
php artisan vendor:publish --tag="filament-translator-config") lets you toggle which attributes (e.g., placeholder, tooltip) are required vs. optional.'required' => [
'tooltip' => true, // Now tooltips are mandatory
],
Check Generated Keys:
dd(TranslatorPlugin::get()->resolveKey('filament.resources.post.pages.create.label')) to inspect resolution.Verify Path Aliases:
TranslatorPlugin::make()
->pathAliases(['App\\Livewire' => 'livewire'])
->register();
// Check with: TranslatorPlugin::get()->pathAliases
Disable Auto-Creation in Production:
createMissingTranslationKeys() feature only runs in local environments by default. Override with:
TranslatorPlugin::make()->createMissingTranslationKeys(fn () => false);
Custom Schema Components:
config/filament-translator.php:
'components' => [
\App\Filament\Components\CustomField::class => [
'label' => false,
'helper_text' => true,
],
],
Override Resolution:
key() to force a specific translation key:
Text::make('Or')->key('custom.or.content');
Fallback Behavior:
Infolist Scope (Future-Proofing):
InfolistScope until explicitly supported. Use the shared form/infolist context for now.How can I help you explore Laravel packages today?