EasyCorp / EasyAdminBundle

EasyAdmin is a fast, beautiful and modern admin generator for Symfony applications.
MIT License
4.09k stars 1.03k forks source link

Autogenerate field labels as translation keys #5451

Open natepage opened 2 years ago

natepage commented 2 years ago

Short description of what this feature will allow to do: Right now EasyAdmin autogenerate field labels as a humanized version of the property name when no label is explicitly set. This feature would autogenerate field labels as translation key based on a predictable format so applications could control those translations without having to explicitly set those keys in their CRUD controllers.

The format of those generated translation key could be something like admin.field.<entity>.<property>.

Ideally this new feature could be toggled at the Dashboard and/or Crud level, and be disabled by default to prevent any BC break.

Example of how to use this feature

Here is how this feature could be toggled:

final class DashboardController extends AbstractDashboardController
{
    public function configureDashboard(): Dashboard
    {
        $dashboard = parent::configureDashboard();

        // Enable feature on dashboard
        $dashboard->generateFieldLabelAsTranslationKeys(true);

        return $dashboard;
    }
}

final class EntityCrudController extends AbstractCrudController
{
    public function configureCrud(Crud $crud): Crud
    {
        $crud->generateFieldLabelAsTranslationKeys(true);

        return $crud;
    }
}

If the feature is enabled, then by default the fields (and filters as they use the field label) would look like this:

Screen Shot 2022-10-28 at 3 03 52 pm

And let's assume the translations are defined in PHP, the applications can simply define the following structure in their messages.en.php:

// translations/messages.en.php

return [
    'admin' => [
        'field' => [
            'post' => [
                'content' => 'Content',
                'description' => 'Description',
                'id' => 'ID',
                'slug' => 'Slug',
                'status' => 'Status',
                'title' => 'Title',
                'createdAt' => 'Created At',
                'updatedAt' => 'Updated At',
            ],
        ],
    ],
];

To then have their field labels being translated:

Screen Shot 2022-10-28 at 3 04 29 pm

natepage commented 2 years ago

@javiereguiluz Hi, thank you for looking at this issue. Is it fair to assume, as you added the label and milestone, that you are not against it? 😄

If that is the case, I would be happy to hear from you regardind specifics, and then I can work on a PR if you like.

ksn135 commented 2 years ago

👍