<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
dyahunter35 / filament-translation-toolkit example snippets
'locales' => ['en', 'ar'], // First locale = base language
// app/Providers/Filament/AdminPanelProvider.php
use Dyahunter35\FilamentTranslationToolkit\Pages\TranslationDashboard;
public function panel(Panel $panel): Panel
{
return $panel
// ... other config
->pages([
TranslationDashboard::class,
]);
}
namespace App\Models;
use Dyahunter35\FilamentTranslationToolkit\Concerns\Translatable;
use Illuminate\Database\Eloquent\Model;
class Company extends Model
{
use Translatable;
// Optional: customize the translation file name
// public static ?string $translationFileName = 'company';
// Optional: disable translation for this model
// public static bool $translationEnabled = false;
}
$model->getTranslationFileName(); // Get the translation file name
Company::getTranslationFileBasename(); // Get the base file name (snake_case)
Company::isTranslatable(); // Check if translation is enabled
namespace App\Filament\Resources;
use Dyahunter35\FilamentTranslationToolkit\Concerns\HasResource;
use Filament\Resources\Resource;
class CompanyResource extends Resource
{
use HasResource;
public static function getModel(): string
{
return \App\Models\Company::class;
}
public static function form(array $form): array
{
return $form->schema([
// ... your form fields — labels auto-translated!
]);
}
}
namespace App\Filament\Resources\CompanyResource\RelationManagers;
use Dyahunter35\FilamentTranslationToolkit\Concerns\HasRelationManager;
use Filament\Resources\RelationManagers\RelationManager;
class DocumentsRelationManager extends RelationManager
{
use HasRelationManager;
protected static string $relationship = 'documents';
}
class InternalDashboard extends Resource
{
use HasResource;
public static bool $translationEnabled = false; // disables translation
// ...
}
'enabled' => false,
class CompanyResource extends Resource
{
use HasResource;
public static function boot(): void
{
static::bootTranslation(); // calls all 3 configure methods
}
}
use Dyahunter35\FilamentTranslationToolkit\Concerns\Translatable;
class Company extends Model
{
use Translatable;
// Optional: customize the translation file name
public static ?string $translationFileName = 'company_info';
// Optional: disable translation for this specific model
public static bool $translationEnabled = false;
}
// Auto-boot all translation callbacks (optional — global auto-registration handles this)
static::bootTranslation();
// Or call individually:
static::translateConfigureForm(); // Auto-translate form fields
static::translateConfigureTable(); // Auto-translate table columns
static::translateConfigureInfolist(); // Auto-translate infolist entries
// Disable translation for this specific class:
public static bool $translationEnabled = false;
// Check if translation is enabled:
if (static::shouldTranslate()) { ... }
// Extract all translatable strings from a form
$strings = static::extractTranslatableStrings($form);
// Create a multi-language form component
$component = static::multiLanguageFormComponent($field, ['en', 'ar']);
class EditCompany extends EditRecord
{
use HasResourcePage;
// Locale path comes from the parent Resource
// Automatically translates navigation label and title
}
class CompanyReport extends Page
{
use HasPage;
protected static string $resource = CompanyResource::class;
// Locale path comes from the parent Resource's model
}