1

DoctrineExtensionsのTranslatableを使用して、トランスレーションされたフィールドを持つエンティティを持っています。これは、それがどのように見えるかです: DoctrineExtensionsで翻訳されたDoctrineエンティティのクローン化翻訳可能

/** 
* @ORM\Table 
* @ORM\Entity(repositoryClass="AppBundle\Entity\Repository\SurveyAnswerRepository") 
* @Gedmo\Loggable 
*/ 
class SurveyAnswer 
{ 
    /** 
    * @var integer 
    * 
    * @ORM\Column(name="id", type="integer") 
    * @ORM\Id 
    * @ORM\GeneratedValue(strategy="AUTO") 
    */ 
    private $id; 

    /** 
    * @var string 
    * 
    * @ORM\Column(type="string", length=200) 
    * @Gedmo\Versioned 
    * @Gedmo\Translatable 
    */ 
    private $name; 

    /** 
    * @Gedmo\Locale 
    * Used locale to override Translation listener`s locale 
    * this is not a mapped field of entity metadata, just a simple property 
    * and it is not necessary because globally locale can be set in listener 
    */ 
    private $locale; 

    public function __clone() 
    { 
     if ($this->getId()) 
     { 
      $this->id = null; 
     } 
    } 

    public function setTranslatableLocale($locale) 
    { 
     $this->locale = $locale; 
    } 

    public function getId() 
    { 
     return $this->id; 
    } 

    public function setName($name) 
    { 
     $this->name = $name; 

     return $this; 
    } 

    public function getName() 
    { 
     return $this->name; 
    } 

} 

私は、このようなエンティティのクローンを作成

は、新しいものはsymfonyのアプリケーションに設定された現在のロケールに翻訳のみで構成されています。他のすべての言語の翻訳はありません。

+0

?あなたはそれらにアクセスできますか? –

+0

別表にありますが、私は手作業でのコピーを避けたいと思います(可能であれば、欠けている翻訳を見つけて補完するためのいくつかのコードを書くことを意味します)。 – Marek

答えて

0

Gedmoリポジトリ機能を使用すると、翻訳可能なすべてのフィールドを取得し、新しいエンティティ用に変換することができます。お使いのコントローラクローン機能(例えばSurveyController :: duplicateAction)で

:翻訳が保存されているか

$newEntity = clone $entity; 
$em = $this->getDoctrine()->getManager(); 
$transRepo = $em->getRepository('Gedmo\Translatable\Entity\Translation'); 

// Get all translations from original entity 
$translations = $transRepo->findTranslations($entity); 
foreach ($translations as $locale => $fields) { 
    foreach ($fields as $field => $value) { 
     // Add new translation for new entity, per locale, per field 
     $transRepo->translate($newEntity, $field, $locale, $value); 
    } 
} 
$em->flush(); 
関連する問題