1111
1212namespace Symfony \Bundle \FrameworkBundle \Command ;
1313
14+ use Symfony \Component \Console \Output \ConsoleOutputInterface ;
1415use Symfony \Component \Console \Style \SymfonyStyle ;
1516use Symfony \Component \Translation \Catalogue \TargetOperation ;
1617use Symfony \Component \Translation \Catalogue \MergeOperation ;
@@ -85,10 +86,11 @@ public function isEnabled()
8586 protected function execute (InputInterface $ input , OutputInterface $ output )
8687 {
8788 $ io = new SymfonyStyle ($ input , $ output );
89+ $ errorIo = $ output instanceof ConsoleOutputInterface ? new SymfonyStyle ($ input , $ output ->getErrorOutput ()) : $ io ;
8890
8991 // check presence of force or dump-message
9092 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 ' );
9294
9395 return 1 ;
9496 }
@@ -97,7 +99,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
9799 $ writer = $ this ->getContainer ()->get ('translation.writer ' );
98100 $ supportedFormats = $ writer ->getFormats ();
99101 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 ).'. ' ));
101103
102104 return 1 ;
103105 }
@@ -127,12 +129,12 @@ protected function execute(InputInterface $input, OutputInterface $output)
127129 }
128130 }
129131
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 ));
132134
133135 // load any messages from templates
134136 $ extractedCatalogue = new MessageCatalogue ($ input ->getArgument ('locale ' ));
135- $ io ->comment ('Parsing templates... ' );
137+ $ errorIo ->comment ('Parsing templates... ' );
136138 $ extractor = $ this ->getContainer ()->get ('translation.extractor ' );
137139 $ extractor ->setPrefix ($ input ->getOption ('no-prefix ' ) ? '' : $ input ->getOption ('prefix ' ));
138140 foreach ($ transPaths as $ path ) {
@@ -144,7 +146,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
144146
145147 // load any existing messages from the translation files
146148 $ currentCatalogue = new MessageCatalogue ($ input ->getArgument ('locale ' ));
147- $ io ->comment ('Loading translation files... ' );
149+ $ errorIo ->comment ('Loading translation files... ' );
148150 $ loader = $ this ->getContainer ()->get ('translation.loader ' );
149151 foreach ($ transPaths as $ path ) {
150152 $ path .= 'translations ' ;
@@ -165,7 +167,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
165167
166168 // Exit if no messages found.
167169 if (!count ($ operation ->getDomains ())) {
168- $ io ->warning ('No translation messages were found. ' );
170+ $ errorIo ->warning ('No translation messages were found. ' );
169171
170172 return ;
171173 }
@@ -199,7 +201,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
199201 }
200202
201203 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> ' );
203205 }
204206
205207 $ resultMessage = sprintf ('%d message%s successfully extracted ' , $ extractedMessagesCount , $ extractedMessagesCount > 1 ? 's were ' : ' was ' );
@@ -211,7 +213,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
211213
212214 // save the files
213215 if ($ input ->getOption ('force ' ) === true ) {
214- $ io ->comment ('Writing files... ' );
216+ $ errorIo ->comment ('Writing files... ' );
215217
216218 $ bundleTransPath = false ;
217219 foreach ($ transPaths as $ path ) {
@@ -232,7 +234,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
232234 }
233235 }
234236
235- $ io ->success ($ resultMessage .'. ' );
237+ $ errorIo ->success ($ resultMessage .'. ' );
236238 }
237239
238240 private function filterCatalogue (MessageCatalogue $ catalogue , $ domain )
0 commit comments