4. Translate PHPCR models

Doctrine PHPCR ODM handles translations natively so you don’t need to install anything else.

4.1. Implement the TranslatableInterface

Todo do so SonataTranslationBundle brings the Sonata\TranslationBundle\Model\Phpcr\TranslatableInterface you can implement.

4.2. Define translatable Fields

Please check the Doctrine PHPCR ODM documentation how you can define your fields you want to translate.

4.3. Advanced Configuration

If you already followed Installation, you just have to pay attention to PHPCR fallback configuration.

So if you configured SonataTranslation like this :

  • YAML
    1
    2
    3
    4
    # config/packages/sonata_translation.yaml
    
    sonata_translation:
        locales: [fr, en, it, nl, es]
    

Then you should configure doctrine_phpcr.odm.locales for the same list.

  • YAML
     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    # config/packages/doctrine_phpcr.yaml
    
    doctrine_phpcr:
        odm:
            locales:
                fr: [en, it]
                en: []
                it: [fr, en]
                nl: [en]
                es: [en, fr, it]