2014-08-28 91 views
0

我在Symfony的2.5與a2lix_translations和Gedmo教義的擴展Symfony2的翻譯形式

  • gedmo /教義的擴展工作 「: 」DEV-主
  • a2lix /翻譯形式束「:」 2。 * @ dev

我正在嘗試在實體集合中添加一個帶有值名稱和說明的翻譯。

這裏是我的實體集:

/** 
* Collection 
* 
* @ORM\Table() 
* @ORM\Entity(repositoryClass="Angeli\AdminBundle\Entity\CollectionRepository") 
* @Gedmo\TranslationEntity(class="Angeli\AdminBundle\Entity\CollectionTranslation") 
*/ 
class Collection 
{ 
* @var integer 
* 
* @ORM\Column(name="id", type="integer") 
* @ORM\Id 
* @ORM\GeneratedValue(strategy="AUTO") 
*/ 
private $id; 

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

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

/** 
* @ORM\OneToMany(targetEntity="CollectionTranslation", mappedBy="object", cascade={"persist", "remove"}) 
*/ 
protected $translations; 

/** 
* Required for Translatable behaviour 
* @Gedmo\Locale 
*/ 
protected $locale; 

public function __construct() 
{ 
    $this->translations = new ArrayCollection(); 
} 

/** 
* Get id 
* 
* @return integer 
*/ 
public function getId() 
{ 
    return $this->id; 
} 

/** 
* Set name 
* 
* @param string $name 
* @return Collection 
*/ 
public function setName($name) 
{ 
    $this->name = $name; 

    return $this; 
} 

/** 
* Get name 
* 
* @return string 
*/ 
public function getName() 
{ 
    return $this->name; 
} 

/** 
* Set description 
* 
* @param string $description 
* @return Collection 
*/ 
public function setDescription($description) 
{ 
    $this->description = $description; 

    return $this; 
} 

/** 
* Get description 
* 
* @return string 
*/ 
public function getDescription() 
{ 
    return $this->description; 
} 

public function getTranslations() 
{ 
    return $this->translations; 
} 

public function addTranslation(CollectionTranslation $t) 
{ 
    $this->translations->add($t); 
    $t->setObject($this); 
} 

public function removeTranslation(CollectionTranslation $t) 
{ 
    $this->translations->removeElement($t); 
} 

public function setTranslations($translations) 
{ 
    $this->translations = $translations; 
} 

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

這裏是我的CollectionTranslation類:

/** 
* @ORM\Entity 
* @ORM\Table(name="collection_translations", 
*  uniqueConstraints={@ORM\UniqueConstraint(name="lookup_unique_idx", columns={ 
*   "locale", "object_id", "field" 
*  })} 
*) 
*/ 
class CollectionTranslation extends AbstractPersonalTranslation 
{ 
    /** 
    * Convinient constructor 
    * 
    * @param string $locale 
    * @param string $field 
    * @param string $content 
    */ 
    public function __construct($locale = null, $field = null, $content = null) 
    { 
     $this->setLocale($locale); 
     $this->setField($field); 
     $this->setContent($content); 
    } 

    /** 
    * @ORM\ManyToOne(targetEntity="Collection", inversedBy="translations") 
    * @ORM\JoinColumn(name="object_id", referencedColumnName="id", onDelete="CASCADE") 
    */ 
    protected $object; 
} 

現在我正在努力建設一個形式:

class CollectionType extends AbstractType{ 

public function buildForm(FormBuilderInterface $builder, array $options) 
{ 
    //$builder->add('name','text', array('required' => true, 'label'=>'Name')); 
    //$builder->add('description','textarea', array('required' => true, 'label'=>'Description')); 
    $builder->add('translations', 'a2lix_translations'); 


} 

public function setDefaultOptions(OptionsResolverInterface $resolver) 
{ 
    $resolver->setDefaults(array(
     'data_class' => 'Angeli\AdminBundle\Entity\Collection', 
    )); 
} 

public function getName() 
{ 
    return 'Collection'; 
} 

} 

不過我的表格存在3種語言標籤 和輸入字段

  • 內容

如果我添加

  • 場=名稱
  • 內容=一些文字

我只翻譯了值 「名」

我想要一個帶有我的語言選項卡和「名稱」和「描述」的表單作爲翻譯表單中的輸入字段。

有人看到我在做什麼錯了?

回答

0

試試這個:你正在使用3種語言的英文,法文和德文。

添加在您的形式:

$builder->add('translations', 'a2lix_translations', array(
     'locales' => array('en_US','fr_FR', 'de'), 
     'required_locales'=>array('en_US'), 
     'fields' => array(
      'name' => array(
       'field_type' => 'text', 
       'label' => 'Name',      
       'locale_options' => array(
        'fr' => array(
         'label' => 'nom' 
        ), 
        'de' => array(
         'label' => 'Name' 
       ), 
       )), 
      'description' => array(
       'field_type' => 'textarea', 
       'label' => 'Description',      
       'locale_options' => array(
        'fr' => array(
         'label' => 'description' 
       ), 
        'de' => array(
         'label' => 'Beschreibung' 
       ), 
      )), 
      ))); 

和渲染鑑於像

form_label(form.translations) 

form_widget(form.translations) 
0

我有同樣的問題,因爲你的。 請嘗試:

"gedmo/doctrine-extensions": "dev-master", 
"a2lix/translation-form-bundle": "1.*@dev" 

$builder->add('translations', 'a2lix_translations_gedmo', array(
    'translatable_class' => 'Angeli\AdminBundle\Entity\Collection', 
)); 

你也不需要__constructCollectionTranslation