Created
October 7, 2024 15:09
-
-
Save sadegh19b/fde3c39f8e8ed3d5b60765ac7f1d4a0c to your computer and use it in GitHub Desktop.
Filament Resource Labels Translation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Filament\Concerns; | |
use Lang; | |
trait ResourceLabelsTranslation | |
{ | |
public static function getModelLabel(): string | |
{ | |
return static::getTranslateLabel('singular') ?? parent::getModelLabel(); | |
} | |
public static function getPluralModelLabel(): string | |
{ | |
return static::getTranslateLabel('plural') ?? parent::getPluralModelLabel(); | |
} | |
public static function getNavigationLabel(): string | |
{ | |
return static::getTranslateLabel('navigation') ?? parent::getNavigationLabel(); | |
} | |
private static function getTranslateLabel($type): string|null | |
{ | |
if (! in_array($type, ['singular', 'plural', 'navigation'])) { | |
return null; | |
} | |
$resourceName = static::getSlug(); | |
$transKey = "filament.resources.{$resourceName}.{$type}"; | |
return Lang::has($transKey) ? Lang::get($transKey) : null; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment