-
Notifications
You must be signed in to change notification settings - Fork 33
Closed
Description
When using a placeholder attr for a form field, the extractor doesn't respect the domain.
The translation is then in the wrong domain file and cannot be retrieved at layout.
Example
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('name',
TextType::class,
array('required' => false,
'attr' => array(
'placeholder' => 'label.hint.name'
),
"label" => "label.name",
'translation_domain' => 'contact'
)
)
...
}
In this case, label.name is extracted in the contact.en.xlf file and label.hint.name in the messages.en.xlf file.
But when rendered, even if the hints are translated, it's not rendered because the translator wants it to be in the contact domain.
As a workaround I had to add:
public function buildForm(FormBuilderInterface $builder, array $options)
{
/** @var Translator $translator */
$translator = $options['translator'];
//workaround for placeholders :(
$translator->trans('label.hint.name', array(), 'contact');
$builder
->add(...);
}
It fixes the issue, but these entries are now duplicated (in messages.en.xlf and contact.en.xlf)
I also tried to directly set the placeholder with a result of $translator->trans(), but this way I get a Form placeholder is not a scalar string error.
Metadata
Metadata
Assignees
Labels
No labels