Search code examples
symfonysymfony-cmf

Cannot convert application to multi-lang and keep current content translatable


We have an application built on Symfony-CMF which is running fine. We now have a requirement to add locales and translations to the content. We have set up one page (/contact) with various locale specific routes (e.g. /en/contact and /fr/contact) and we are able to visit those URLs and edit the content for each language independently. However, we are not able to see the existing content so when we hit /en/contact all the editable content areas are blank.

By rebuilding our app and loading the content (via fixtures) with the relevant multi-lang config in place, we are able to see the original content in place but when we edit it, it seems to edit it for each language. So when we go to /en/contact and edit the content there, we see that change reflected at /fr/contact and vice versa.

We have added the following config:

doctrine_phpcr:
  odm:
    locales:
        en: ~
        fr: [en]
        de: [en]

cmf_core: 
  multilang:
    locales: [en, fr, de]

We have BasicPage class for our documents:

/**
* @PHPCR\Document(referenceable=true,translator="attribute")
*/
class BasicPage extends Page implements SeoAwareInterface, SitemapElementInterface
{
  /**
   * @var string
   * @PHPCR\String(nullable=true,translated=true)
   */
  protected $intro;
  ...
}

Is there something else we need to do to make the original content translatable?


Solution

  • Ok so I managed to figure this out myself (partly due to the info provided by dbu and partly thanks to xdebug!) The cmf_create inline editor was generating ajax requests to update the documents but these were using the default locale rather than the locale specified in the request. Setting cmf_create.rest_force_request_locale to true as specified in the CMF docs worked and means we can edit each language separately when loaded from our fixtures. We still need a migration to make each document translatable but we may be able to leverage the converter tool as mentioned by dbu.