11
11
12
12
namespace Symfony \Bundle \FrameworkBundle \Command ;
13
13
14
+ use Symfony \Component \Console \Output \ConsoleOutputInterface ;
14
15
use Symfony \Component \Console \Style \SymfonyStyle ;
15
16
use Symfony \Component \Translation \Catalogue \TargetOperation ;
16
17
use Symfony \Component \Translation \Catalogue \MergeOperation ;
@@ -85,10 +86,11 @@ public function isEnabled()
85
86
protected function execute (InputInterface $ input , OutputInterface $ output )
86
87
{
87
88
$ io = new SymfonyStyle ($ input , $ output );
89
+ $ errorIo = $ output instanceof ConsoleOutputInterface ? new SymfonyStyle ($ input , $ output ->getErrorOutput ()) : $ io ;
88
90
89
91
// check presence of force or dump-message
90
92
if ($ input ->getOption ('force ' ) !== true && $ input ->getOption ('dump-messages ' ) !== true ) {
91
- $ io ->error ('You must choose one of --force or --dump-messages ' );
93
+ $ errorIo ->error ('You must choose one of --force or --dump-messages ' );
92
94
93
95
return 1 ;
94
96
}
@@ -97,7 +99,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
97
99
$ writer = $ this ->getContainer ()->get ('translation.writer ' );
98
100
$ supportedFormats = $ writer ->getFormats ();
99
101
if (!in_array ($ input ->getOption ('output-format ' ), $ supportedFormats )) {
100
- $ io ->error (array ('Wrong output format ' , 'Supported formats are: ' .implode (', ' , $ supportedFormats ).'. ' ));
102
+ $ errorIo ->error (array ('Wrong output format ' , 'Supported formats are: ' .implode (', ' , $ supportedFormats ).'. ' ));
101
103
102
104
return 1 ;
103
105
}
@@ -127,12 +129,12 @@ protected function execute(InputInterface $input, OutputInterface $output)
127
129
}
128
130
}
129
131
130
- $ io ->title ('Translation Messages Extractor and Dumper ' );
131
- $ io ->comment (sprintf ('Generating "<info>%s</info>" translation files for "<info>%s</info>" ' , $ input ->getArgument ('locale ' ), $ currentName ));
132
+ $ errorIo ->title ('Translation Messages Extractor and Dumper ' );
133
+ $ errorIo ->comment (sprintf ('Generating "<info>%s</info>" translation files for "<info>%s</info>" ' , $ input ->getArgument ('locale ' ), $ currentName ));
132
134
133
135
// load any messages from templates
134
136
$ extractedCatalogue = new MessageCatalogue ($ input ->getArgument ('locale ' ));
135
- $ io ->comment ('Parsing templates... ' );
137
+ $ errorIo ->comment ('Parsing templates... ' );
136
138
$ extractor = $ this ->getContainer ()->get ('translation.extractor ' );
137
139
$ extractor ->setPrefix ($ input ->getOption ('no-prefix ' ) ? '' : $ input ->getOption ('prefix ' ));
138
140
foreach ($ transPaths as $ path ) {
@@ -144,7 +146,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
144
146
145
147
// load any existing messages from the translation files
146
148
$ currentCatalogue = new MessageCatalogue ($ input ->getArgument ('locale ' ));
147
- $ io ->comment ('Loading translation files... ' );
149
+ $ errorIo ->comment ('Loading translation files... ' );
148
150
$ loader = $ this ->getContainer ()->get ('translation.loader ' );
149
151
foreach ($ transPaths as $ path ) {
150
152
$ path .= 'translations ' ;
@@ -165,7 +167,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
165
167
166
168
// Exit if no messages found.
167
169
if (!count ($ operation ->getDomains ())) {
168
- $ io ->warning ('No translation messages were found. ' );
170
+ $ errorIo ->warning ('No translation messages were found. ' );
169
171
170
172
return ;
171
173
}
@@ -199,7 +201,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
199
201
}
200
202
201
203
if ($ input ->getOption ('output-format ' ) == 'xlf ' ) {
202
- $ io ->comment ('Xliff output version is <info>1.2</info> ' );
204
+ $ errorIo ->comment ('Xliff output version is <info>1.2</info> ' );
203
205
}
204
206
205
207
$ resultMessage = sprintf ('%d message%s successfully extracted ' , $ extractedMessagesCount , $ extractedMessagesCount > 1 ? 's were ' : ' was ' );
@@ -211,7 +213,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
211
213
212
214
// save the files
213
215
if ($ input ->getOption ('force ' ) === true ) {
214
- $ io ->comment ('Writing files... ' );
216
+ $ errorIo ->comment ('Writing files... ' );
215
217
216
218
$ bundleTransPath = false ;
217
219
foreach ($ transPaths as $ path ) {
@@ -232,7 +234,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
232
234
}
233
235
}
234
236
235
- $ io ->success ($ resultMessage .'. ' );
237
+ $ errorIo ->success ($ resultMessage .'. ' );
236
238
}
237
239
238
240
private function filterCatalogue (MessageCatalogue $ catalogue , $ domain )
0 commit comments