我正在尝试将以下 phpcr 结构放在一起,其中包括冻结某些版本的文档作为参考,然后将其推送到外部系统 api 进行翻译。一旦一个语言环境的翻译完成,它就会被发回,并且相关的语言环境节点会更新为翻译内容和版本参考。
ROOT:
mstr:
a-doc
ref:
a-doc:
1.0:
1.3:
1.7:
locale:
es-ES
a-doc
所以这一切都在工作。
现在我正在添加 CmfRountingBundle,但无法弄清楚如何使区域设置路由工作(添加区域设置模式选项)。
我想我必须创建一个自定义 TranslationStrategy,在我的情况下,我只需要 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 中获得异常。
关于如何让这个工作的任何建议?!