Search code examples
symfonylocalizationtranslationsonata-admin

Sonata Admin translations with default content


I was able to setup Sonata Admin with translated entities using Gedmo Doctrine Extensions:

# Doctrine Extensions Configuration
stof_doctrine_extensions:
    default_locale: '%locale%'
    orm:
        default:
            timestampable: true
            blameable: true
            translatable: true

# Sonata Translation Configuration
sonata_translation:
    locales: [en, fr, it]
    default_locale: '%locale%'
    gedmo:
        enabled: true

However every time I create a new entity, the translatable fields in the other languages starts empty.

English language selected:

enter image description here

Italian language selected:

enter image description here

It becomes very difficult to translate items if I don't know what they are in English.

Is there an option so that when I create an entity in English it populates also the entities in the other languages with the same content?


Solution

  • You should add fallback option to fields you need:

    /**
     * @var string
     *
     * @Assert\NotBlank()
     *
     * @Gedmo\Translatable(fallback=true)
     *
     * @ORM\Column(type="string", length=255)
     */
    private $title;