Add locale switcher in Sonata Admin Form

I have translatable Entities (with Gedmo) and now I want to edit them with Sonata Admin.

I need to set values for de and fr, so I installed sonata-project/translation-bundle and followed the instructions, but I can’t make the locale switcher visible. This is my current config:

sonata_admin:
    dashboard:
        blocks:
            - { type: sonata.admin.block.admin_list, position: left }
    assets:
        extra_stylesheets:
            - bundles/sonatatranslation/css/sonata-translation.css

sonata_block:
    blocks:
        sonata.admin.block.admin_list:
            contexts: [admin]

sonata_translation:
    locales: ['fr', 'de']
    default_locale: '%locale%'
    locale_switcher: true

I even tried an individual template

{% extends '@SonataAdmin/CRUD/base_edit.html.twig' %}

{% block show %}
    {{ sonata_block_render({ 'type': 'sonata_translation.block.locale_switcher' }) }}
{% endblock %}

activated with

templates:
    edit: 'Admin/edit/edit_translate.html.twig'

but then I get

"The block type "sonata_translation.block.locale_switcher" does not exist"

Source: Symfony Questions

Was this helpful?

0 / 0

Leave a Reply 0

Your email address will not be published. Required fields are marked *