New

Just launched: Vueblocks, a brand-new search engine for Vue packages! Explore Vueblocks →

madbox-99/filament-translatable-model-labels

Resolve Filament Resource model labels (singular and plural) through Laravel translations.
1,002
Install
composer require madbox-99/filament-translatable-model-labels
Latest Version:v1.3.0
PHP:^8.3
Laravel:11 · 12 · 13
License:MIT
Last Updated:Sep 7, 2026
Links: GitHub  ·  Packagist
Maintainer: MadBox-99

Filament Translatable Model Labels

Resolve Filament Resource model labels (singular and plural) — and therefore the navigation item and table heading — through Laravel's __() translation, keyed off the auto-derived model name. Define the translation once; every Resource picks it up without per-Resource overrides.

Installation

composer require madbox-99/filament-translatable-model-labels

Usage

Apply the trait to a shared base Resource so it is never repeated:

use Filament\Resources\Resource;
use MadBox99\FilamentTranslatableModelLabels\Concerns\TranslatesFilamentModelLabels;

abstract class BaseResource extends Resource
{
    use TranslatesFilamentModelLabels;
}

Or extend the provided base class:

use MadBox99\FilamentTranslatableModelLabels\TranslatableFilamentResource;

class IssueResource extends TranslatableFilamentResource
{
    protected static ?string $model = \App\Models\Issue::class;
}

Add the translations to your app's lang/hu.json:

{
    "issue": "probléma",
    "issues": "problémák"
}

Result: the create button reads "Új probléma", and the navigation item and table heading read "Problémák".

Automatic injection on make:filament-resource

This works out of the box — no configuration needed. Once the package is installed, php artisan make:filament-resource adds the trait to every generated resource automatically. The generated class still extends the original Filament Resource; the package just adds the trait:

class OrderResource extends Resource
{
    use TranslatesFilamentModelLabels;

    protected static ?string $model = Order::class;
    // ...
}

The trait is a no-op when no translation exists (it returns the stock label), so it is harmless even on resources you don't translate.

Turning it off

If you'd rather add the trait manually, publish the config and disable it:

php artisan vendor:publish --tag=filament-translatable-model-labels-config
// config/filament-translatable-model-labels.php
return [
    'inject_trait_into_generated_resources' => false,
];

Note: this hooks Filament's internal resource generator (Filament\Commands\FileGenerators\Resources\ResourceClassGenerator) via the container. It is a generation-time (dev) convenience with no runtime effect.

Retrofitting existing resources (Rector)

The generator integration only affects newly generated resources. To add the trait to all of your existing resources in one pass, use the bundled Rector rule.

Add it to your rector.php:

use MadBox99\FilamentTranslatableModelLabels\Rector\AddTranslatesFilamentModelLabelsTraitRector;
use Rector\Config\RectorConfig;

return RectorConfig::configure()
    ->withPaths([__DIR__ . '/app'])
    ->withImportNames()
    ->withRules([
        AddTranslatesFilamentModelLabelsTraitRector::class,
    ]);

Then run it:

vendor/bin/rector

Every class that extends Filament\Resources\Resource and does not already use the trait gets use TranslatesFilamentModelLabels; added. Resources that already use it, and non-resource classes, are left untouched. Requires rector/rector in your project.

How it works

  • The singular label is __(<humanised model name>) — e.g. Issue → __('issue').
  • The plural label is __(locale_has_pluralization() ? Str::plural(<humanised model name>) : <humanised model name>) — uses the pluralized form when the active locale supports pluralization, otherwise the singular form.
  • An explicit $modelLabel / $pluralModelLabel on the Resource still wins.
  • If no translation exists, __() returns the key unchanged, so untranslated locales behave exactly like stock Filament.

Capitalised translation keys

By default the key follows Filament's own convention and is lower-cased, because that is the case Filament renders and then capitalises at the call site ("Create customer", navigation "Customers").

Apps that translate FIELD labels with ->translateLabel() already have a capitalised namespace — that helper keys off Str::headline(), so Select::make('customer_id') looks up __('Customer'). In such an app the default would mean a second, lower-cased copy of every noun you have already translated. Set key_case instead:

// config/filament-translatable-model-labels.php
return [
    'key_case' => 'ucfirst',
];

Customer then resolves __('Customer') / __('Customers'), and BlogPost resolves __('Blog post') / __('Blog posts') — only the first word is capitalised, matching Str::headline().

Only the lookup changes. When the capitalised key has no translation the label falls back to Filament's lower-cased one, so an untranslated locale still renders exactly like stock Filament.

Multi-word models

The key is the humanised, lower-cased model name with spaces, e.g. BlogPost becomes __('blog post') / __('blog posts'):

{
    "blog post": "blogbejegyzés",
    "blog posts": "blogbejegyzések"
}

Testing

composer test

License

MIT.

Related Packages

prunacatalin/filament-locale-switcher

Drop-in topbar locale switcher for Filament v4/v5 panels. Session + per-user per...

4,689 2
gsarigul84/translation-manager

Manage your application's translation strings in Filament.

17 0
rodrigofs/filament-smart-translate

A comprehensive Laravel package for automatic translation support in Filament v4...

32 9
abdulmajeed-jamaan/filament-translatable-tabs

Simplifying managing json based translation columns using tabs

142,295 41
lukasss93/laravel-larex

Translate your Laravel application from a single CSV file!

125,617 98

Version History

Version Released PHP License
v1.3.0 ^8.3 MIT
v1.2.0 ^8.3 MIT
v1.1.0 ^8.3 MIT
v1.0.0 ^8.3 MIT