tomatophp/filament-translations
Filament plugin to manage Laravel translations in the database with caching. Scan your code for trans()/__() keys, import strings, and edit translations via a UI. Built on spatie/laravel-translation-loader, with install command and panel plugin registration.
composer require tomatophp/filament-translations
php artisan filament-translations:install
app/Providers/Filament/AdminPanelProvider.php:
$panel->plugin(\TomatoPHP\FilamentTranslations\FilamentTranslationsPlugin::make());
php artisan vendor:publish --tag="filament-translations-views"
php artisan vendor:publish --tag="filament-translations-lang"
php artisan vendor:publish --tag="filament-translations-migrations"
trans(), __(), and other translation keys in your PHP files.Scanning and Importing:
php artisan filament-translations:import
config/filament-translations.php:
'use_queue_on_scan' => true,
Editing Translations:
Customizing the UI:
use TomatoPHP\FilamentTranslations\Filament\Resources\Translations\Table\TranslationTable;
public function boot()
{
TranslationTable::register([
\Filament\Tables\Columns\TextColumn::make('custom_column'),
]);
}
'translation_resource' => App\Filament\Resources\CustomTranslationResource::class,
Permissions and Access Control:
$panel->plugin(\TomatoPHP\FilamentTranslations\FilamentTranslationsPlugin::make()->allowClearTranslations(false));
Integration with Translation Services:
$panel->plugin(\TomatoPHP\FilamentTranslations\FilamentTranslationsPlugin::make()->useGptTranslation());
Missing Translations After Scan:
spatie/laravel-translation-loader is installed and configured.scan_paths in config/filament-translations.php includes your project’s directories:
'scan_paths' => [
app_path('Lang'),
resource_path('lang'),
],
UI Not Appearing:
composer dump-autoload after installation.AdminPanelProvider.Performance Issues with Large Translation Sets:
'use_queue_on_scan' => true,
translations table.Custom Excel Imports/Exports Not Working:
Maatwebsite\Excel\Concerns\ToModel or FromCollection.'path_to_custom_excel_import' => App\Imports\CustomTranslationImport::class,
Translation Keys Not Detected:
.php files by default (since v4.0.1).Log Scanning Results:
Enable debug mode in config/filament-translations.php:
'debug' => true,
Check logs for scanned keys and errors.
Clear Cache: After customizing hooks or resources, run:
php artisan optimize:clear
php artisan view:clear
Verify Database Structure: Publish migrations and run:
php artisan migrate
Dynamic Navigation Grouping: Override the navigation label/group in config:
'navigation_group' => 'Localization',
'navigation_icon' => 'heroicon-o-globe-alt',
Conditional UI Elements: Use Filament’s visibility rules to show/hide buttons based on user roles:
\Filament\Tables\Actions\Action::make('clear_all')
->visible(fn () => auth()->user()->isAdmin()),
Extending the Scanner:
Create a custom scanner by extending TomatoPHP\FilamentTranslations\Services\TranslationScanner and update the config:
'scanner_class' => App\Services\CustomTranslationScanner::class,
Localization of the Plugin Itself: Publish and translate the plugin’s language files:
php artisan vendor:publish --tag="filament-translations-lang"
Add translations to resources/lang/{locale}/filament-translations.php.
Automate Workflows: Use Laravel’s scheduling to run scans periodically:
// app/Console/Kernel.php
$schedule->command('filament-translations:import')->daily();
Backup Translations: Export translations regularly via the "Export" button and store backups in version control.
Collaborative Translations: Combine with Filament Spatie Media Library to attach translation files to entries.
Fallback Logic:
Configure fallback locales in config/app.php to ensure translations always resolve:
'fallback_locales' => ['en'],
```markdown
How can I help you explore Laravel packages today?