'How to translate the Main Menu Labels in Symfony EasyAdmin?
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 ?
Solution 1:[1]
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
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 |