Skip to content

Commit ddf0d42

Browse files
committed
- add translation to transformers
1 parent 61c6865 commit ddf0d42

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

src/Bridge/Transformer/AbstractTransformer.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,31 @@
1111
*/
1212
abstract class AbstractTransformer implements FormToQuestionTransformer
1313
{
14+
/** @var TranslatorInterface */
15+
private $translator;
16+
17+
/**
18+
* NumberTransformer constructor.
19+
* @param TranslatorInterface $translator
20+
*/
21+
public function __construct(TranslatorInterface $translator)
22+
{
23+
$this->translator = $translator;
24+
}
25+
1426
/**
1527
* @param FormInterface $form
1628
*
1729
* @return string
1830
*/
1931
protected function questionFrom(FormInterface $form)
2032
{
21-
$question = FormUtil::label($form);
33+
$question = $this->translator->trans(FormUtil::label($form));
2234

2335
return $this->formattedQuestion($question, $this->defaultValueFrom($form));
2436
}
2537

38+
2639
/**
2740
* @param FormInterface $form
2841
*

src/Bundle/services.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,14 @@ services:
3030

3131
matthias_symfony_console_form.text_transformer:
3232
class: Matthias\SymfonyConsoleForm\Bridge\Transformer\TextTransformer
33+
arguments: [ "@translator" ]
3334
public: false
3435
tags:
3536
- { name: form_to_question_transformer, form_type: Symfony\Component\Form\Extension\Core\Type\TextType }
3637

3738
matthias_symfony_console_form.date_time_transformer:
3839
class: Matthias\SymfonyConsoleForm\Bridge\Transformer\DateTimeTransformer
40+
arguments: [ "@translator" ]
3941
public: false
4042
tags:
4143
- { name: form_to_question_transformer, form_type: Symfony\Component\Form\Extension\Core\Type\TimeType }
@@ -44,12 +46,14 @@ services:
4446

4547
matthias_symfony_console_form.password_transformer:
4648
class: Matthias\SymfonyConsoleForm\Bridge\Transformer\PasswordTransformer
49+
arguments: [ "@translator" ]
4750
public: false
4851
tags:
4952
- { name: form_to_question_transformer, form_type: Symfony\Component\Form\Extension\Core\Type\PasswordType }
5053

5154
matthias_symfony_console_form.choice_transformer:
5255
class: Matthias\SymfonyConsoleForm\Bridge\Transformer\ChoiceTransformer
56+
arguments: [ "@translator" ]
5357
public: false
5458
tags:
5559
- { name: form_to_question_transformer, form_type: Symfony\Component\Form\Extension\Core\Type\ChoiceType }
@@ -125,4 +129,4 @@ services:
125129
public: false
126130
arguments:
127131
- "@form.factory"
128-
- "@form.registry"
132+
- "@form.registry"

0 commit comments

Comments
 (0)