Michał Zwierzyński
Michał Zwierzyński

Reputation: 101

Symfony - Sonata-Admin menu group translation

i have a problem with translation of group in admin menu. Its translates labels but not groups:

services: sonata.admin.language: class: App\Bundle\LanguageBundle\Admin\LanguageAdmin tags: - name: sonata.admin manager_type: orm group: "admin.menu.group.language" label: "admin.menu.group.item.languages" arguments: - ~ - App\Bundle\LanguageBundle\Entity\Language - ~

sonata.admin.language_pair:
    class: App\Bundle\LanguageBundle\Admin\LanguagePairAdmin
    tags:
        - name: sonata.admin
          manager_type: orm
          group: "admin.menu.group.language"
          label: "admin.menu.group.item.language_pairs"
    arguments:
        - ~
        - App\Bundle\LanguageBundle\Entity\LanguagePair
        - ~

anyone can help???

Upvotes: 4

Views: 2168

Answers (5)

Andreas
Andreas

Reputation: 2153

For me a combination of @Andrey and @Catalins answer did the trick:

config/packages/sonata_admin.yaml

sonata_admin:
    ...

    dashboard:
        blocks:
        -
            position: left
            type: sonata.admin.block.admin_list

        groups:
            app.admin.group.cms:
                label: 'app.admin.group.cms'
                label_catalogue: 'messages' # <--- this is not the bundle name, but the "translation domain" / filename of the translation file
                items:
                    - app.admin.page
                roles: ['ROLE_ADMIN']

    ...

and in translations/messages.en.yml:

app:
  admin:
    group:
      cms: CMS
    pages:
      label: Pages

Upvotes: 1

Vadim Sushin
Vadim Sushin

Reputation: 53

The menu groups labels are translated using 'SonataAdminBundle' domain, but items labels - using 'messages' domain or domain defined in $translationDomain variable in your Admin class.

Upvotes: 1

Catalin
Catalin

Reputation: 121

Unfortunately, the suggested answers didn't work for me: it still was not translated. Here's what I had to do:

  1. For some reason, label_catalogue: "messages" and even a call to [setTranslationDomain, [messages]] didn't change anything: Symfony would still look for the string to translate inside of SonataAdminBundle.en.yml (I use yml files).

  2. Therefore, create a file SonataAdminBundle.en.yml (or xml, whichever you use) inside app/Resources/translations/, and add your group string in there:

    admin:
        menu:
            group:
                language: Language
    
  3. In your config.yml, add these lines under sonata_admin:

    sonata_admin:
        [...]
        dashboard:
            groups:
                admin.menu.group.language: ~
    
  4. Clear cache. Important! It somehow was not translating it until I did this.

Also use Symfony translation debugger to learn where it's looking for some strings.

Hope this helps!

Upvotes: 1

Andrey Kazmerchuk
Andrey Kazmerchuk

Reputation: 101

When I added

label_catalogue: "YourBundleName"

into 'tags' section, it helps me to translate label of group.

Upvotes: 2

Matth&#233;o Geoffray
Matth&#233;o Geoffray

Reputation: 159

you can add a "translation" node:

translation: YourBundle

Upvotes: -1

Related Questions