php - Symfony 2 JMSTranslationsBundle Form with choice how to create translation terms? -


i have simple form choice type simple entity:

public function buildform(formbuilderinterface $builder, array $options) {     $builder         ->add('name', 'entity', [             'class' => 'appbundle\entity\type',                 'property' => 'name',                 'expanded' => true         ]     ); } 

the entity type database table idtype ai column , name column.

the database content pretty simple:

idtype      name "1"         "term.inquiry" "2"         "term.tender" 

and result in twig file looks pretty simple too:

{{ form_start(form) }}     {{ form_widget(form.name) }} {{ form_end(form) }} 

i'm stucked in how implement translation method translate term.inquiry , term.tender

i've looked documentation here, don't know how implement (the correct way) gettranslationmessages method via translationcontainerinterface. i've tried answer here didn't know how match return array choices in buildform method.

any suggestions or hints best practice implementation? many in advance

you're maybe searching option choice_translation_domain introduced in symfony 2.7 choice_label deprecating property.

see http://symfony.com/doc/current/reference/forms/types/choice.html#choice-translation-domain

if translations in src/appbundle/resources/translations/entity.en.yml, containing :

term:     inquiry: 'a name'     tender: 'another name' 

you can write :

public function buildform(formbuilderinterface $builder, array $options) {     $builder         ->add('name', 'entity', array(             'class' => 'appbundle\entity\type',             //'property' => 'name', deprecated use 'choice_label' instead             'expanded' => true,             'choice_label' => 'name',             'choice_translation_domain' => 'entity',         )); } 

Comments

Popular posts from this blog

Hatching array of circles in AutoCAD using c# -

ios - UITEXTFIELD InputView Uipicker not working in swift -

Python Pig Latin Translator -