2014-08-28 98 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