Skip to content

Commit 56433b5

Browse files
Merge pull request #23 from mops1k/fix_label_translations
Add translation to transformers
2 parents 61c6865 + 37cc15d commit 56433b5

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

src/Bridge/Transformer/AbstractTransformer.php

+15-1
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,34 @@
55
use Matthias\SymfonyConsoleForm\Console\Formatter\Format;
66
use Matthias\SymfonyConsoleForm\Form\FormUtil;
77
use Symfony\Component\Form\FormInterface;
8+
use Symfony\Component\Translation\TranslatorInterface;
89

910
/**
1011
* Reusable code for FormToQuestionTransformers.
1112
*/
1213
abstract class AbstractTransformer implements FormToQuestionTransformer
1314
{
15+
/** @var TranslatorInterface */
16+
private $translator;
17+
18+
/**
19+
* NumberTransformer constructor.
20+
*
21+
* @param TranslatorInterface $translator
22+
*/
23+
public function __construct(TranslatorInterface $translator)
24+
{
25+
$this->translator = $translator;
26+
}
27+
1428
/**
1529
* @param FormInterface $form
1630
*
1731
* @return string
1832
*/
1933
protected function questionFrom(FormInterface $form)
2034
{
21-
$question = FormUtil::label($form);
35+
$question = $this->translator->trans(FormUtil::label($form));
2236

2337
return $this->formattedQuestion($question, $this->defaultValueFrom($form));
2438
}

src/Bundle/services.yml

+9-1
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,20 @@ services:
2828
arguments:
2929
- "@form.factory"
3030

31+
matthias_symfony_console_form.abstract_transformer:
32+
abstract: true
33+
arguments: [ "@translator" ]
34+
3135
matthias_symfony_console_form.text_transformer:
3236
class: Matthias\SymfonyConsoleForm\Bridge\Transformer\TextTransformer
37+
parent: matthias_symfony_console_form.abstract_transformer
3338
public: false
3439
tags:
3540
- { name: form_to_question_transformer, form_type: Symfony\Component\Form\Extension\Core\Type\TextType }
3641

3742
matthias_symfony_console_form.date_time_transformer:
3843
class: Matthias\SymfonyConsoleForm\Bridge\Transformer\DateTimeTransformer
44+
parent: matthias_symfony_console_form.abstract_transformer
3945
public: false
4046
tags:
4147
- { name: form_to_question_transformer, form_type: Symfony\Component\Form\Extension\Core\Type\TimeType }
@@ -44,12 +50,14 @@ services:
4450

4551
matthias_symfony_console_form.password_transformer:
4652
class: Matthias\SymfonyConsoleForm\Bridge\Transformer\PasswordTransformer
53+
parent: matthias_symfony_console_form.abstract_transformer
4754
public: false
4855
tags:
4956
- { name: form_to_question_transformer, form_type: Symfony\Component\Form\Extension\Core\Type\PasswordType }
5057

5158
matthias_symfony_console_form.choice_transformer:
5259
class: Matthias\SymfonyConsoleForm\Bridge\Transformer\ChoiceTransformer
60+
parent: matthias_symfony_console_form.abstract_transformer
5361
public: false
5462
tags:
5563
- { name: form_to_question_transformer, form_type: Symfony\Component\Form\Extension\Core\Type\ChoiceType }
@@ -125,4 +133,4 @@ services:
125133
public: false
126134
arguments:
127135
- "@form.factory"
128-
- "@form.registry"
136+
- "@form.registry"

0 commit comments

Comments
 (0)