This package is tailored for Filament Admin Panel v3.x.
Make sure you have installed the admin panel before you continue with the installation. You can check the documentation here
The package translates the Eloquent models using a currently specified translation file. The Eloquent models are used internally in filament's Resources and RelationManagers for translation. This package provides traits for the Resources and RelationManagers to translate them automatically.
PHP Versions | Laravel Versions |
---|---|
8.3, 8.2, 8.1 | 10.* |
8.3, 8.2 | 11.* |
You can install the package via composer:
composer require maggomann/filament-model-translator
Add the plugin to your desired Filament panel:
use Maggomann\FilamentModelTranslator\FilamentModelTranslatorServicePlugin;
class AdminPanelProvider extends PanelProvider
{
public function panel(Panel $panel): Panel
{
return $panel
...
->plugins([
FilamentModelTranslatorServicePlugin::make()
]);
}
}
The translations are currently called from the filament-model.php
translation file, which must be located in the following directory tree:
lang
de
filament-model.php
en
filament-model.php
The filament-model.php
file within the package serves as a structured language file for translations. It enables defining translations for various entities such as models, their attributes, and navigation elements.
<?php
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',
],
],
];
This file offers a structured way to organize language translations for various aspects of your application:
- Models: Here, you can define translations for the names of your models, both in singular and plural forms.
- Attributes: Contains translations for the different attributes of each model. For instance, you can set translations for attributes like name, slug, created_at, etc.
- Navigation: Defines translations for the navigation groups associated with the models. In this case, the navigation group for each model is set to 'Seasons & Tournaments'.
The trait HasTranslateableResources
internally translates the method calls automatically:
public static function getModelLabel(): string;
public static function getPluralModelLabel(): string;
protected static function getNavigationGroup(): ?string;
Example:
<?php
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;
Or:
<?php
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;
<?php
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;
The trait HasTranslateableRelationManager
internally translates the method calls automatically:
public static function getModelLabel(): string;
public static function getPluralModelLabel(): string;
You can use the trait HasTranslateableRelationManager
in the following ways:
Example:
<?php
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::';
}
<?php
namespace Maggomann\YourPackageFolder\Resources\FederationResource\RelationManagers;
use Maggomann\YourPackageFolder\Resources\TranslateableRelationManager;
class LeaguesRelationManager extends TranslateableRelationManager
{
Or:
<?php
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::';
The following method calls are available with the trait HasTranslateableModel
:
<?php
EloquentModel::transAttribute('your_attributes_key');
// Example
TextInput::make('name')
->label(Federation::transAttribute('name'))
->required();
You can use the trait HasTranslateableModel
in the following ways:
Example:
<?php
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::';
}
<?php
namespace Maggomann\YourPackageFolder\Models;
class Federation extends TranslateableModel
{
Or:
<?php
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::';
composer test
Please see CHANGELOG for more information on what has changed recently.
Please see CONTRIBUTING for details.
Please review our security policy on how to report security vulnerabilities.
The MIT License (MIT). Please see License File for more information.
Please note that these packages for Filament are not officially operated by Filament and do not provide any support or warranty from the Filament team. The use of these packages is at your own risk.
This project represents unofficial extensions for Filament and is maintained by an independent community of developers. We strive to maintain compatibility with the current versions of Filament, but we cannot guarantee that the packages will function flawlessly or be compatible with future versions of Filament.
We recommend users to create backups of their projects and thoroughly test them before using these packages. If you have any questions, issues, or suggestions, we are available to assist you. However, please note that we cannot provide official support for these packages.
We would like to emphasize that Filament is a separate developer community independent of this project. For more information about Filament, please refer to the official Filament website.
Please read the license terms to learn more about the conditions for using these packages.