0

I'm trying to put together the following phpcr structure, which consists of freezing out certain versions of documents as references that are then pushed to external system apis for translation. Once a translation is complete for a locale it is sent back and the relevant locale node is updated with translation content and version reference.

ROOT:
    mstr:
        a-doc
    ref:
        a-doc:
           1.0:
           1.3:
           1.7:
    locale:
        es-ES
           a-doc

So thats all up and working.

Now I'm adding the CmfRountingBundle, and can't figure out how to get the locale routing to work (the add locale pattern option).

I figure I have to create a custom TranslationStrategy, and in my case I just need the loadTranslation method to find the related document in the locale path.

So this is what I've got:

<?php

namespace My\Project\Translation\TranslationStrategy;

use Doctrine\ODM\PHPCR\Translation\TranslationStrategy\TranslationStrategyInterface;
use Doctrine\ODM\PHPCR\Mapping\ClassMetadata;
use PHPCR\NodeInterface;

class CustomTranslationStrategy implements TranslationStrategyInterface
{
   /**
    * {@inheritdoc}
    */
   public function loadTranslation($document, NodeInterface $node, ClassMetadata $metadata, $locale)
   {
       throw new \Exception('Load translation not yet implemented ...');
   }
   ....

I added a translator attribute to my document:

/**
 * @PHPCR\Document(
 *   versionable="full",
 *   translator="custom",
 *   mixins={"mix:created", "mix:lastModified"}
 * )
 */
class Page implements ContentInterface, VersionableContentInterface {

    /**
     * The language this document currently is in
     * @PHPCR\Locale()
     */
    protected $locale;

Updated my config.yml

parameters:
    translation_locales: [zh-CN,de-DE,es-ES,fr-FR,it-IT,ja-JP,ko-KR,en-UK,en-US]

doctrine_phpcr:
    session:
        backend: "%phpcr_backend%"
        workspace: "%phpcr_workspace%"
        username: "%phpcr_user%"
        password: "%phpcr_password%"
    odm:
        auto_mapping: true
        auto_generate_proxy_classes: "%kernel.debug%"
        locales:
            en: [de, fr]
            de: [en, fr]
            fr: [en, de]
            #es: [en]

cmf_core:
  persistence:
    phpcr: 
        translation_strategy: My\Project\Translation\TranslationStrategy\CustomTranslationStrategy
    # if you want another basepath
    # basepath: /custom/basepath
    publish_workflow: false

cmf_routing:
    chain:
        routers_by_id:
            cmf_routing.dynamic_router: 20
            router.default: 100
    dynamic:
        locales: %translation_locales%
        persistence:
            phpcr:
                use_sonata_admin: auto
                content_basepath: /mstr
                admin_basepath: /cms/routes
        templates_by_class:
            %my_page_document%:  MyDemoBundle:Page:simple.html.twig

Now when I go to /fr-FR/a-doc I just see the english content of the document and when i go to /es-ES/a-doc I get a 500 error: The locale 'es-ES' is not present in the list of available locales (i have it commented in the odm locales).

I'm obviously missing the $dm->setTranslationStrategy call the documentation mentions, just not sure how to inject it into the cmf routing bundle so that I get my Exception in loadTranslation.

Any advice on how i can get this working?!

dantelo
  • 60
  • 8
  • the translation_strategy you can configure on cmf_core is meant for something different: force all models in your application to use a specific strategy (see http://symfony.com/doc/current/cmf/bundles/core/persistence.html#choosing-a-global-translation-strategy) – dbu Jan 10 '15 at 11:42
  • looking at the https://github.com/doctrine/DoctrinePHPCRBundle , a configuration option to add custom translation strategies is missing. can you open an issue there, or even open a pull request? (happy to discuss this further on github if you want) – dbu Jan 10 '15 at 11:45
  • and did you see the version api? the ref: section looks a bit like you are reinventing that in userland. its only supported in jackalope-jackrabbit at the moment, but could be implemented in jackalope-doctrine-dbal too – dbu Jan 10 '15 at 11:49
  • @dbu thanks for the reply. I am using jackrabbit, i want this custom workflow because i want a versioned master record that is independent and the translation procedure to be frozen reference nodes and independent versioned locale nodes. Ideally i want to just be able to override/configure the way the routing bundle finds the translation node. – dantelo Jan 10 '15 at 12:44
  • Will open an issue on github, but perhaps it belongs in the CmfRoutingBundle? And will investigate more this week and see if i can pin point a solution to open a pull request – dantelo Jan 10 '15 at 12:47
  • great. i will reply tomorrow on https://github.com/symfony-cmf/RoutingBundle/issues/282 and https://github.com/sonata-project/SonataDoctrinePhpcrAdminBundle/issues/148#issuecomment-69318490 – dbu Jan 11 '15 at 14:48

0 Answers0