21
21
use Symfony \Component \Translation \MessageCatalogue ;
22
22
23
23
/**
24
- * A command that parse templates to extract translation messages and add them into the translation files.
24
+ * A command that parses templates to extract translation messages and adds them
25
+ * into the translation files.
25
26
*
26
27
* @author Michel Salib <michelsalib@hotmail.com>
27
28
*/
@@ -81,7 +82,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
81
82
$ writer = $ this ->getContainer ()->get ('translation.writer ' );
82
83
$ supportedFormats = $ writer ->getFormats ();
83
84
if (!in_array ($ input ->getOption ('output-format ' ), $ supportedFormats )) {
84
- $ output ->error (array ('Wrong output format ' , 'Supported formats are ' .implode (', ' , $ supportedFormats ).'. ' ));
85
+ $ output ->error (array ('Wrong output format ' , 'Supported formats are: ' .implode (', ' , $ supportedFormat
10000
s ).'. ' ));
85
86
86
87
return 1 ;
87
88
}
@@ -111,12 +112,12 @@ protected function execute(InputInterface $input, OutputInterface $output)
111
112
}
112
113
}
113
114
114
- $ output ->title ('Symfony translation update command ' );
115
- $ output ->text (sprintf ('Generating "<info>%s</info>" translation files for "<info>%s</info>" ' , $ input ->getArgument ('locale ' ), $ currentName ));
115
+ $ output ->title ('Translation Messages Extractor and Dumper ' );
116
+ $ output ->comment (sprintf ('Generating "<info>%s</info>" translation files for "<info>%s</info>" ' , $ input ->getArgument ('locale ' ), $ currentName ));
116
117
117
118
// load any messages from templates
118
119
$ extractedCatalogue = new MessageCatalogue ($ input ->getArgument ('locale ' ));
119
- $ output ->text ('Parsing templates ' );
120
+ $ output ->comment ('Parsing templates... ' );
120
121
$ extractor = $ this ->getContainer ()->get ('translation.extractor ' );
121
122
$ extractor ->setPrefix ($ input ->getOption ('prefix ' ));
122
123
foreach ($ transPaths as $ path ) {
@@ -128,7 +129,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
128
129
129
130
// load any existing messages from the translation files
130
131
$ currentCatalogue = new MessageCatalogue ($ input ->getArgument ('locale ' ));
131
- $ output ->text ('Loading translation files ' );
132
+ $ output ->comment ('Loading translation files... ' );
132
133
$ loader = $ this ->getContainer ()->get ('translation.loader ' );
133
134
foreach ($ transPaths as $ path ) {
134
135
$ path .= 'translations ' ;
@@ -144,18 +145,22 @@ protected function execute(InputInterface $input, OutputInterface $output)
144
145
145
146
// Exit if no messages found.
146
147
if (!count ($ operation ->getDomains ())) {
147
- $ output ->warning ('No translation found. ' );
148
+ $ output ->warning ('No translation messages were found. ' );
148
149
149
150
return ;
150
151
}
151
152
152
153
// show compiled list of messages
153
- if ($ input ->getOption ('dump-messages ' ) === true ) {
154
+ if (true === $ input ->getOption ('dump-messages ' )) {
155
+ $ extractedMessagesCount = 0 ;
154
156
$ output ->newLine ();
155
157
foreach ($ operation ->getDomains () as $ domain ) {
156
- $ output ->section (sprintf ('Displaying messages for domain <info>%s</info>: ' , $ domain ));
157
158
$ newKeys = array_keys ($ operation ->getNewMessages ($ domain ));
158
159
$ allKeys = array_keys ($ operation ->getMessages ($ domain ));
160
+ $ domainMessagesCount = count ($ newKeys ) + count ($ allKeys );
161
+
162
+ $ output ->section (sprintf ('Messages extracted for domain "<info>%s</info>" (%d messages) ' , $ domain , $ domainMessagesCount ));
163
+
159
164
$ output ->listing (array_merge (
160
165
array_diff ($ allKeys , $ newKeys ),
161
166
array_map (function ($ id ) {
@@ -165,11 +170,15 @@ protected function execute(InputInterface $input, OutputInterface $output)
165
170
return sprintf ('<fg=red>%s</> ' , $ id );
166
171
}, array_keys ($ operation ->getObsoleteMessages ($ domain )))
167
172
));
173
+
174
+ $ extractedMessagesCount += $ domainMessagesCount ;
168
175
}
169
176
170
177
if ($ input ->getOption ('output-format ' ) == 'xlf ' ) {
171
- $ output ->writeln ('Xliff output version is <info>1.2</info> ' );
178
+ $ output ->comment ('Xliff output version is <info>1.2</info> ' );
172
179
}
180
+
181
+ $ resultMessage = sprintf ('%d messages were successfully extracted ' , $ extractedMessagesCount );
173
182
}
174
183
175
184
if ($ input ->getOption ('no-backup ' ) === true ) {
@@ -178,7 +187,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
178
187
179
188
// save the files
180
189
if ($ input ->getOption ('force ' ) === true ) {
181
- $ output ->text ('Writing files ' );
190
+ $ output ->comment ('Writing files... ' );
182
191
183
192
$ bundleTransPath = false ;
184
193
foreach ($ transPaths as $ path ) {
@@ -191,9 +200,14 @@ protected function execute(InputInterface $input, OutputInterface $output)
191
200
if ($ bundleTransPath ) {
192
201
$ writer ->writeTranslations ($ operation ->getResult (), $ input ->getOption ('output-format ' ), array ('path ' => $ bundleTransPath , 'default_locale ' => $ this ->getContainer ()->getParameter ('kernel.default_locale ' )));
193
202
}
203
+
204
+ if (true === $ input ->getOption ('dump-messages ' )) {
205
+ $ resultMessage .= ' and translation files were updated. ' ;
206
+ } else {
207
+ $ resultMessage = 'Translation files were successfully updated. ' ;
208
+ }
194
209
}
195
210
196
- $ output ->newLine ();
197
- $ output ->success ('Success ' );
211
+ $ output ->success ($ resultMessage );
198
212
}
199
213
}
0 commit comments