PHP code example of mominalzaraa / filament-localization

1. Go to this page and download the library: Download mominalzaraa/filament-localization library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

mominalzaraa / filament-localization example snippets


return [
    'default_locale' => 'en',
    'locales' => ['en', 'el', 'fr'],
    'structure' => 'panel-based', // flat, nested, or panel-based
    'backup' => true,
    'git' => [
        'enabled' => true,
        'commit_message' => 'chore: add Filament localization support',
    ],
    'excluded_panels' => [],
    'excluded_resources' => [],
    'translation_key_prefix' => 'filament',
    
    // Skip Terms - Terms that should remain the same across languages
    'skip_identical_terms' => [
        'API', 'URL', 'HTTP', 'HTTPS', 'PDF', 'CSV', 'JSON', 'XML',
        'Laravel', 'Filament', 'Vue', 'React', 'Angular', 'Google', 'Microsoft',
        'GitHub', 'Docker', 'AWS', 'Azure', 'PayPal', 'Stripe', 'WordPress',
        'Bootstrap', 'Tailwind', 'jQuery', 'TypeScript', 'Webpack', 'Vite',
        'JWT', 'OAuth', 'REST', 'GraphQL', 'SEO', 'UX', 'UI', 'SaaS', 'PaaS',
        'IoT', 'AI', 'ML', 'DevOps', 'CI/CD', 'Agile', 'Scrum', 'TDD', 'BDD',
        'GDPR', 'ISO', 'IEEE', 'W3C', 'OWASP', 'NIST', 'ITIL', 'PMP',
    ],
    
    // DeepL Translation Configuration
    'deepl' => [
        'api_key' => env('DEEPL_API_KEY'),
        'base_url' => env('DEEPL_BASE_URL', 'https://api-free.deepl.com/v2'),
        'timeout' => 60,
        'batch_size' => 50,
        'preserve_formatting' => true,
    ],
];

   FilamentLanguageSwitcherPlugin::make()
       ->locales([
           ['code' => 'en', 'name' => 'English', 'flag' => 'gb'],
           ['code' => 'el', 'name' => 'Greek', 'flag' => 'gr'],
       ])
   

// Before
protected static ?string $modelLabel = 'Articles';

// After  
protected static ?string $modelLabel = null;

public static function getModelLabel(): string
{
    return __('filament/admin/user_resource.model_label');
}

// Before
class Dashboard extends BaseDashboard
{
    protected static ?string $title = 'Blog Dashboard';
    protected static ?string $navigationLabel = 'Dashboard';
}

// After
class Dashboard extends BaseDashboard
{
    protected static ?string $title = null;
    protected static ?string $navigationLabel = null;

    public function getTitle(): string
    {
        return __('filament/admin/dashboard.title');
    }

    public static function getNavigationLabel(): string
    {
        return __('filament/admin/dashboard.navigation_label');
    }
}

// Source (English)
return [
    'title' => 'Blog Dashboard',
    'navigation_label' => 'Send Email',
    'description' => 'Manage your blog posts and comments',
];

// Target (Greek) - Before Translation
return [
    'title' => 'Blog Dashboard',           // ← Will be translated (identical to source)
    'navigation_label' => 'Send Email',    // ← Will be translated (not in skip terms)
    'description' => 'Διαχείριση των δημοσιεύσεων σας', // ← Will be preserved (properly translated)
];

// Target (Greek) - After Translation
return [
    'title' => 'Πίνακας Ελέγχου Ιστολογίου',            // ← Translated
    'navigation_label' => 'Αποστολή Email',  // ← Translated
    'description' => 'Διαχείριση των δημοσιεύσεων σας', // ← Preserved
];

use CraftForge\FilamentLanguageSwitcher\FilamentLanguageSwitcherPlugin;

public function panel(Panel $panel): Panel
{
    return $panel
        ->plugins([
            FilamentLanguageSwitcherPlugin::make()
                ->locales([
                    ['code' => 'en', 'name' => 'English', 'flag' => 'gb'],
                    ['code' => 'el', 'name' => 'Greek', 'flag' => 'gr'],
                ]),
        ]);
}

TextInput::make('name')->)->searchable(),
Action::make('delete')->

TextInput::make('name')
    ->label(__('filament/admin/user_resource.name'))
    ->   ->searchable(),

Action::make('delete')
    ->label(__('filament/admin/user_resource.delete'))
    ->

// lang/en/filament/admin/user_resource.php
return ['name' => 'Name', 'email' => 'Email', 'delete' => 'Delete'];

// lang/el/filament/admin/user_resource.php  
return ['name' => 'Όνομα', 'email' => 'Email', 'delete' => 'Διαγραφή'];
bash
php artisan vendor:publish --tag="filament-localization-config"
bash
   php artisan filament:localize --panel=admin
   

lang/
├── en/filament/admin/user_resource.php
├── en/filament/blog/post_resource.php
└── el/filament/admin/user_resource.php