A Filament plugin that enables Translation Overrides management in Laravel applications with an elegant admin interface. Supports both multi-tenant and single-tenant applications.
lang/vendor/*
)You can install the package via composer:
composer require jaysontemporas/translation-overrides
Publish the configuration file:
php artisan translation-overrides:install
This will publish the config file to config/translation-overrides.php
and the migration file to create the Translation Overrides table.
Important: Before running migrations, you should review and update the configuration file to set your preferred table name, tenancy mode, and other settings.
Run the migrations after configuring:
php artisan migrate
After publishing the configuration file, you can configure the package in config/translation-overrides.php
:
return [ // Cache duration in seconds 'cache_duration' => 21600, // 6 hours // Filament navigation settings 'navigation' => [ 'group' => 'Settings', ], // Access control 'can_access' => [ 'role' => 'Super Admin', ], // Tenancy configuration 'tenancy_enabled' => false, // Set to true for multi-tenant apps // Your tenant model (only needed if tenancy_enabled is true) 'tenant_model' => null, // \App\Models\Team::class // Table name for storing Translation Overrides 'table_name' => 'translation_overrides', 'tenant_id_column' => null, // Ex. tenant_id, only used if tenancy_enabled is true // Supported languages 'supported_languages' => [ 'en' => 'English', 'es' => 'Spanish', 'fr' => 'French', // Add more languages as needed ],];
If you're using this package in a single-tenant application, set tenancy_enabled
to false
in your configuration:
// config/translation-overrides.phpreturn [ 'tenancy_enabled' => false, // ... other configuration];
In this mode:
HasTenantTranslation
contract is not required in your ModelIf you're using this package in a multi-tenant application, ensure tenancy_enabled
is true
:
// config/translation-overrides.phpreturn [ 'tenancy_enabled' => true, 'tenant_model' => \App\Models\Team::class, 'table_name' => 'translation_overrides', 'tenant_id_column' => 'tenant_id', // ... other configuration];
Your User model should implement the HasTenantTranslation
contract:
use JaysonTemporas\TranslationOverrides\Contracts\HasTenantTranslation; class User extends Authenticatable implements HasTenantTranslation{ // ... public function getTranslationTenantId(): int|null { if (Filament::getTenant()) { return Filament::getTenant()->id; } return null; // OR in simple tenancy structure, users table has tenant_id // return $this->tenant_id; }}
Add the TranslationOverrides plugin to your Filament panel:
use JaysonTemporas\TranslationOverrides\TranslationOverridesPlugin;Â public function panel(Panel $panel): Panel{ return $panel // ... ->plugins([ TranslationOverridesPlugin::make(), ]) // ...}
This will automatically register the TranslationOverride resource in your Filament admin panel under the configured navigation group (default: "Settings").
You can override the default TranslationOverrideResource by creating your own resource class and configuring the plugin to use it. This is useful when you need to customize access controls, modify the interface, or add additional functionality.
use JaysonTemporas\TranslationOverrides\TranslationOverridesPlugin;Â public function panel(Panel $panel): Panel{ return $panel ->plugins([ TranslationOverridesPlugin::make() ->usingResource(CustomTranslationOverrideResource::class), ]);}
Create a custom resource class that extends the default one:
use JaysonTemporas\TranslationOverrides\Filament\Resources\TranslationOverrideResource;Â class CustomTranslationOverrideResource extends TranslationOverrideResource{ public static function canAccess(): bool { // Only allow super admins to access translation overrides return auth()->user()?->hasRole('super-admin'); }}
Once installed, you'll have access to a dedicated translations management interface in your Filament admin panel where you can:
For Single-Tenant Applications:
For Multi-Tenant Applications:
Your User model should implement the HasTenantTranslation
contract:
use JaysonTemporas\TranslationOverrides\Contracts\HasTenantTranslation; class User extends Authenticatable implements HasTenantTranslation{ // ... public function getTranslationTenantId(): int { return Filament::getTenant()->id; // OR in simple tenancy structure, users table has tenant_id // return $this->tenant_id; }}
After configuring the Filament interface, you can use translations in your views:
// In blade templates{{ __('message.greeting') }}Â // In PHP code__('message.greeting');
This plugin provides a way to override translations without actually modifying Laravel's original translation files. When a translation key is requested:
Single-Tenant Mode:
Multi-Tenant Mode:
This approach allows you to:
This package supports vendor translations published by Laravel packages. When a package provides its own translations, they are typically published to:
lang/vendor/package-name/enlang/vendor/package-name/es
The package automatically discovers and includes these vendor translations in your Translation Overrides management interface. Vendor translations will appear with their package name as a prefix (e.g., package-name.file.key
).
To publish vendor translations from a package, you can use Laravel's standard vendor publish command:
php artisan vendor:publish --tag=package-name-translations
Once published, these translations will be automatically available in the translation management interface and can be customized per tenant (in multi-tenant mode) or globally (in single-tenant mode).
The MIT License (MIT). Please see License File for more information.
Jayson Temporas is a seasoned full stack web developer with over a decade of experience in the industry. He specializes in Laravel and the TALL stack, crafting modern, scalable applications. Jayson is passionate about web development and continuously explores new technologies to enhance his skills.