【问题标题】:How to translate the Main Menu Labels in Symfony EasyAdmin?如何翻译 Symfony EasyAdmin 中的主菜单标签?
【发布时间】:2022-06-25 20:41:57
【问题描述】:

我正在使用 Symfony EasyAdmin 4,但不知道如何更改主菜单的实体标签。它们默认为其实体的名称。

这似乎可以通过 EasyAdmin 2.x 轻松实现,正如 old docs 所示。但是那里提到的所有文件 (translations/messages.xx.yaml,config/packages/easy_admin.yaml) 都没有在 EasyAdmin 4.x 中使用。

那么,如何翻译 Symfony EasyAdmin 中的主菜单标签?

【问题讨论】:

    标签: symfony easyadmin


    【解决方案1】:

    在 4.x 中我们不再需要这些文件:

    首先:改变default_locale

    在:config/packages/translation.yaml 文件中,设置:

    framework:
            default_locale: xx
    

    xx 是目标语言(例如,es 用于西班牙语,fr 用于法语,de 用于德语等)

    第二个:实现 config crud 方法

    在相关 crud 控制器内的 configureCrud 函数内实现 setEntityLabelInSingularsetEntityLabelInPlural 方法:

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

    别忘了use EasyCorp\Bundle\EasyAdminBundle\Config\Crud;


    更多:Symfony: The Fast Track

    【讨论】:

      猜你喜欢
      • 2021-05-07
      • 2011-10-23
      • 2015-04-09
      • 2015-11-06
      • 2017-12-24
      • 1970-01-01
      • 2016-07-22
      • 1970-01-01
      • 2017-11-24
      相关资源
      最近更新 更多