0

私は次の phpcr 構造をまとめようとしています。これは、翻訳のために外部システム API にプッシュされる参照としてドキュメントの特定のバージョンを凍結することで構成されています。ロケールの翻訳が完了すると、それが返送され、関連するロケール ノードが翻訳内容とバージョン参照で更新されます。

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

それで、それはすべて稼働しています。

現在、CmfRoutingBundle を追加していますが、ロケール ルーティングを機能させる方法がわかりません (ロケール パターンの追加オプション)。

カスタムの TranslationStrategy を作成する必要があると考えています。私の場合は、locale パスで関連ドキュメントを見つけるために loadTranslation メソッドが必要なだけです。

だからこれは私が持っているものです:

<?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 ...');
   }
   ....

ドキュメントに翻訳者属性を追加しました。

/**
 * @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;

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

/fr-FR/a-doc に移動すると、ドキュメントの英語のコンテンツが表示され、/es-ES/a-doc に移動すると、500 エラーが発生します。ロケール 'es-ES' はありません利用可能なロケールのリストに存在します(odmロケールでコメントしました)。

ドキュメントに記載されている $dm->setTranslationStrategy 呼び出しが明らかに欠落しています。それを cmf ルーティング バンドルに挿入して、loadTranslation で例外を取得する方法がわかりません。

これを機能させる方法について何かアドバイスはありますか?!

4

0 に答える 0