Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JMS translation doesn't extract dynamic form build? #444

Closed
ArmandArthur opened this issue May 14, 2017 · 3 comments
Closed

JMS translation doesn't extract dynamic form build? #444

ArmandArthur opened this issue May 14, 2017 · 3 comments

Comments

@ArmandArthur
Copy link

ArmandArthur commented May 14, 2017

Q A
Bundle version dev-master
Symfony version 3.2.8
PHP version ??

I'm not good in english but when i do:

$builder->addEventListener(
FormEvents::PRE_SET_DATA,
function (FormEvent $event) use ($formModifier, $builder ) {
$builder
->add('numero',TextType::class, array(
'label' => 'form.lot.numero'
))
}
);
it's works

and when i do

    $formModifier = function (FormInterface $form, $lot = null) {
        
        if($lot->getId() == null)
        {
            
            $champsOptionnelsLotList = $this->em->getRepository('AppBundle:FiscaliteChampsOptionnels')->findAll();
        }
        else
        {
            $champsOptionnelsLotList = $lot->getProgramme()->getChampsOptionnelsLot()->getValues();
        }
        
        foreach($champsOptionnelsLotList as $key => $champsOptionnelsLot)
        {
            $form->add($champsOptionnelsLot->getNomChampsLot(),TextType::class, array(
                'label' => $champsOptionnelsLot->getKeyTranslation()
            ));
        }
    };

    $builder->addEventListener(
        FormEvents::PRE_SET_DATA,
        function (FormEvent $event) use ($formModifier) {
                $data = $event->getData();
                $formModifier($event->getForm(), $data);
      
        }
    );

it nots works

as i do:
$array = array('var','pour');
foreach($array as $key => $value)
{
$builder->add('numero1', TextType::class, array(
'label' => 'form.'.$value
));
}

it's don't work

it's normal ou it is a bug?

@gnat42
Copy link
Collaborator

gnat42 commented May 15, 2017

This is normal as far as I know. Its not possible to extract labels from files where the data is dynamic. You need to implement Translation/TranslationContainerInterface which provides getTranslationMessages that the extractor will look for.

@gnat42 gnat42 closed this as completed May 15, 2017
@ArmandArthur
Copy link
Author

How i can acces to entity manager form getTranslationMessages, it's a static function..? thanks

@gnat42
Copy link
Collaborator

gnat42 commented May 30, 2017

If your labels are retrieved from a DB, I think you are expected to use other methods to provide them in a translated way. This is to translate the interface and static strings.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants