Installation
composer require kenepa/translation-manager
Publish the config and migrations:
php artisan vendor:publish --provider="Kenepa\TranslationManager\TranslationManagerServiceProvider" --tag="config"
php artisan vendor:publish --provider="Kenepa\TranslationManager\TranslationManagerServiceProvider" --tag="migrations"
php artisan migrate
Register the Plugin
Add to app/Providers/Filament/AdminPanelProvider.php:
public function panel(Panel $panel): Panel
{
return $panel
->plugins([
\Kenepa\TranslationManager\TranslationManagerPlugin::make(),
]);
}
First Use Case
/admin/translation-manager).resources/lang/en/messages.json) to import strings.Translation Management
en, es) with a side-by-side comparison view.auth, validation) using Filament’s table grouping.Integration with Laravel
// config/translation-manager.php
'paths' => [
resource_path('lang/custom'),
],
TranslationManager::updated(function (Translation $translation) {
// Sync with external API or log changes
});
Previewing in Context
PreviewComponent:
use Kenepa\TranslationManager\Components\PreviewComponent;
class CustomPreviewComponent extends PreviewComponent
{
protected function getPreviewTemplate(): string
{
return view('filament.translation-manager.preview.custom');
}
}
Syncing with Git
// app/Providers/AppServiceProvider.php
public function boot()
{
TranslationManager::updated(function () {
Artisan::call('git', ['add', 'resources/lang']);
Artisan::call('git', ['commit', '-m', 'Update translations']);
Artisan::call('git', ['push']);
});
}
Locale File Structure
resources/lang directory mirrors the expected structure (e.g., en/messages.json). The package expects JSON files by default; CSV requires explicit configuration:
'csv' => [
'enabled' => true,
'delimiter' => ',',
],
Permission Issues
admin) via Filament’s built-in policies:
TranslationManagerPlugin::make()->middleware([
EnsureUserHasAccess::class,
]);
Caching Quirks
php artisan config:clear
php artisan view:clear
php artisan filament:cache-reset
Namespace Conflicts
auth.login in both auth.php and messages.json). Use the "Merge" feature to resolve overlaps.Log Translation Changes
Enable debug logging in config/translation-manager.php:
'debug' => [
'log_updates' => true,
],
Check logs at storage/logs/laravel.log.
Validate JSON/CSV
Use the "Validate" button to catch malformed files before import. For custom formats, extend the TranslationImporter:
class CustomImporter extends TranslationImporter
{
public function import(string $path): array
{
// Custom logic (e.g., parse YAML)
return parent::import($path);
}
}
Custom Fields Override the default text input for translations (e.g., add rich text or tags):
use Kenepa\TranslationManager\Components\TranslationForm;
class CustomTranslationForm extends TranslationForm
{
protected function formSchema(): array
{
return [
Textarea::make('translation')
->rows(5)
->toolbarButtons([
'bold', 'italic', 'link',
]),
];
}
}
Webhook Notifications Trigger external actions (e.g., Slack alerts) on translation updates:
TranslationManager::updated(function (Translation $translation) {
Http::post('https://hooks.slack.com/...', [
'text' => "Translation updated: {$translation->key}",
]);
});
Multi-Tenant Support
Scope translations to tenants by overriding the Translation model’s boot() method:
protected static function booted()
{
static::addGlobalScope('tenant', function (Builder $builder) {
$builder->where('tenant_id', tenant()->id);
});
}
How can I help you explore Laravel packages today?