Home > Software engineering >  How to translate the Main Menu Labels in Symfony EasyAdmin?
How to translate the Main Menu Labels in Symfony EasyAdmin?

Time:05-08

I am building an admin backend with Symfony EasyAdmin 4 and couldn't figure out how to change the main menu's entities' labels. They default to their entities' name.

This seems easily achievable with EasyAdmin 2.x, as the docs show. But none of the files mentioned there (translations/messages.xx.yaml,config/packages/easy_admin.yaml) is still in use in EasyAdmin 4.x.

Could the translation be achieved in a different way ?

CodePudding user response:

We don't need any of those files anymore in 4.x:

First: change the default_locale

In the: config/packages/translation.yaml file, set:

framework:
        default_locale: xx

where xx is the target language (e.g es for spanish, fr for french, de for german, etc)

Second: Implement config crud methods

Implement setEntityLabelInSingular and setEntityLabelInPlural methods inside the configureCrud function inside the concerned crud controller:

class YourCrudController extends AbstractCrudController
{     
...   
    public function configureCrud(Crud $crud): Crud
         {
             return $crud
                 ->setEntityLabelInSingular('Your own label')
                 ->setEntityLabelInPlural('Your own labels')
                 ...
                 ;
          }
...
}

Don't forget the : use EasyCorp\Bundle\EasyAdminBundle\Config\Crud;

Source: Symfony: The Fast Track

  • Related