如何更改 a2lix/TranslationFormBundle 的翻译 class 查找目录?

How to change translation class lookup directory for a2lix/TranslationFormBundle?

在 Sonata Admin 中,我想翻译实体字段。为此,我使用 GedmoDoctrineExtension (v2.4.10) 中的“个人翻译”。例如,我的实体“Post”带有可翻译字段“content”和适当的翻译实体 – “PostTranslation”。 “Post”位于“Entity”目录中,但“PostTranslation”位于“Entity/Translation”中。一切正常。为了在管理页面中有实体翻译的形式,我使用 a2lix/TranslationFormBundle (v2.0)。我收到以下错误:

Class AppBundle\Entity\PostTranslation does not exist

list($namespaceAlias, $simpleClassName) = explode(':', $class, 2);
$class = $this->getAliasNamespace($namespaceAlias) .'\'. $simpleClassName;
}
$proxyClass = new \ReflectionClass($class); // Exception is thrown here!
if ($proxyClass->implementsInterface($this->proxyInterfaceName)) {
if (! $parentClass = $proxyClass->getParentClass()) {
return null;

看来,那个bundle默认在“Entity”目录下搜索翻译class,但我需要在“Entity/Translation”里。我怎样才能实现这种行为?

您需要为每个可翻译实体提供一个名为 getTranslationEntityClassgetTranslationClass 的方法,并且该方法必须是静态的。

namespace AppBundle\Entity;

class Post
{
    //...

    /**
     * @return string
     */
    public static function getTranslationClass()
    {
        return __NAMESPACE__ . '\Translation\Post';
    }
}