PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Wednesday, May 11, 2022

[FIXED] How to translate the Main Menu Labels in Symfony EasyAdmin?

 May 11, 2022     easyadmin, symfony     No comments   

Issue

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

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



Answered By - TRKZI Omar
Answer Checked By - Gilberto Lyons (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home
View mobile version

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing