PHP code example of maggomann / filament-model-translator

1. Go to this page and download the library: Download maggomann/filament-model-translator 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/ */

    

maggomann / filament-model-translator example snippets


use Maggomann\FilamentModelTranslator\FilamentModelTranslatorServicePlugin;

class AdminPanelProvider extends PanelProvider
{
    public function panel(Panel $panel): Panel
    {
        return $panel
            ...
            ->plugins([
                FilamentModelTranslatorServicePlugin::make()
            ]);
    }
}



return [
    /*
    |--------------------------------------------------------------------------
    | Models
    |--------------------------------------------------------------------------
    */

    'models' => [
        'calculation_type' => 'Calculation type|Calculation types',
        'federation' => 'Association|Associations',
        'league' => 'League|Leagues',
    ],

    /*
    |--------------------------------------------------------------------------
    | Attribute
    |--------------------------------------------------------------------------
    */

    'attributes' => [
        'federation' => [
            'name' => 'Name',
            'slug' => 'Slug',
            'calculation_type_id' => 'Calculation type',
            'created_at' => 'Created at',
            'updated_at' => 'Updated at',
            'deleted_at' => 'Deleted at',
        ],
        'league' => [
            'name' => 'Name',
            'slug' => 'Slug',
            'created_at' => 'Created at',
            'updated_at' => 'Updated at',
            'deleted_at' => 'Deleted at',
        ],
        'calculation_type' => [
            'name' => 'Name',
            'description' => 'Description',
            'created_at' => 'Created at',
            'updated_at' => 'Updated at',
            'deleted_at' => 'Deleted at',
        ],
    ],

    /*
    |--------------------------------------------------------------------------
    | Navigation
    |--------------------------------------------------------------------------
    */

    'navigation_group' => [
        'federation' => [
            'name' => 'Seasons & Tournaments',
        ],
        'league' => [
            'name' => 'Seasons & Tournaments',
        ],
        'calculation_type' => [
            'name' => 'Seasons & Tournaments',
        ],
    ],
];

public static function getModelLabel(): string;

public static function getPluralModelLabel(): string;

protected static function getNavigationGroup(): ?string;



namespace Maggomann\YourPackageFolder\Resources;

use Filament\Resources\Resource;
use Maggomann\FilamentModelTranslator\Contracts\TranslateableResources;
use Maggomann\FilamentModelTranslator\Traits\HasTranslateableResources;

class TranslateableResource extends Resource implements TranslateableResources
{
    use HasTranslateableResources;

    protected static ?string $translateableKey = 'your-package-name::';

    public function transPackageKey(): ?string
    {
        return static::$translateableKey;
    }
}

class LeagueResource extends TranslateableResource
{
    protected static ?string $model = League::class;

class FederationResource extends TranslateableResource
{
    protected static ?string $model = Federation::class;



namespace Maggomann\YourPackageFolder\Resources;

use Filament\Resources\Resource;
use Maggomann\FilamentModelTranslator\Contracts\TranslateableResources;
use Maggomann\FilamentModelTranslator\Traits\HasTranslateableResources;

class LeagueResource  extends Resource implements TranslateableResources
{
    use HasTranslateableResources;

    protected static ?string $translateableKey = 'your-package-name::';

    public function transPackageKey(): ?string
    {
        return static::$translateableKey;
    }

    protected static ?string $model = League::class;



namespace Maggomann\YourPackageFolder\Resources;

use Filament\Resources\Resource;
use Maggomann\FilamentModelTranslator\Contracts\TranslateableResources;
use Maggomann\FilamentModelTranslator\Traits\HasTranslateableResources;

class FederationResource extends Resource implements TranslateableResources
{
    use HasTranslateableResources;

    protected static ?string $translateableKey = 'your-package-name::';

    public function transPackageKey(): ?string
    {
        return static::$translateableKey;
    }

    protected static ?string $model = Federation::class;

public static function getModelLabel(): string;

public static function getPluralModelLabel(): string;



namespace Maggomann\YourPackageFolder\Resources;

use Filament\Resources\RelationManagers\RelationManager;
use Maggomann\FilamentModelTranslator\Contracts\Translateable;
use Maggomann\FilamentModelTranslator\Traits\HasTranslateableRelationManager;

class TranslateableRelationManager extends RelationManager implements Translateable
{
    use HasTranslateableRelationManager;

    protected static ?string $translateablePackageKey = 'your-package-name::';
}



namespace Maggomann\YourPackageFolder\Resources\FederationResource\RelationManagers;


use Maggomann\YourPackageFolder\Resources\TranslateableRelationManager;

class LeaguesRelationManager extends TranslateableRelationManager
{



namespace Maggomann\YourPackageFolder\Resources\FederationResource\RelationManagers;


use Filament\Resources\RelationManagers\RelationManager;
use Maggomann\FilamentModelTranslator\Contracts\Translateable;
use Maggomann\FilamentModelTranslator\Traits\HasTranslateableRelationManager;

class LeaguesRelationManager extends RelationManager implements Translateable
{
    use HasTranslateableRelationManager;

    protected static ?string $translateablePackageKey = 'your-package-name::';


EloquentModel::transAttribute('your_attributes_key');

// Example
TextInput::make('name')
    ->label(Federation::transAttribute('name'))
    ->



namespace Maggomann\YourPackageFolder\Models;

use Illuminate\Database\Eloquent\Model;
use Maggomann\FilamentModelTranslator\Traits\HasTranslateableModel;

class TranslateableModel extends Model
{
    use HasTranslateableModel;

    protected static ?string $translateablePackageKey = 'your-package-name::';
}



namespace Maggomann\YourPackageFolder\Models;

class Federation extends TranslateableModel
{



namespace Maggomann\YourPackageFolder\Models;

use Illuminate\Database\Eloquent\Model;
use Maggomann\FilamentModelTranslator\Traits\HasTranslateableModel;

class Federation extends Model
{
    use HasTranslateableModel;

    protected static ?string $translateablePackageKey = 'your-package-name::';
console
lang
    de
        filament-model.php
    en
        filament-model.php