Skip to content

Instantly share code, notes, and snippets.

@sadegh19b
Created October 7, 2024 15:09
Show Gist options
  • Save sadegh19b/fde3c39f8e8ed3d5b60765ac7f1d4a0c to your computer and use it in GitHub Desktop.
Save sadegh19b/fde3c39f8e8ed3d5b60765ac7f1d4a0c to your computer and use it in GitHub Desktop.
Filament Resource Labels Translation
<?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