@@ -69,6 +69,8 @@ protected function configure()
69
69
protected function execute (InputInterface $ input , OutputInterface $ output )
70
70
{
71
71
$ output = new SymfonyStyle ($ input , $ output );
72
+ $ kernel = $ this ->getContainer ()->get ('kernel ' );
73
+
72
74
// check presence of force or dump-message
73
75
if ($ input ->getOption ('force ' ) !== true && $ input ->getOption ('dump-messages ' ) !== true ) {
74
76
$ output ->error ('You must choose one of --force or --dump-messages ' );
@@ -87,44 +89,54 @@ protected function execute(InputInterface $input, OutputInterface $output)
87
89
$ kernel = $ this ->getContainer ()->get ('kernel ' );
88
90
89
91
// Define Root Path to App folder
90
- $ rootPath = $ kernel ->getRootDir ();
92
+ $ transPaths = array ( $ kernel ->getRootDir (). ' /Resources/ ' );
91
93
$ currentName = 'app folder ' ;
92
94
93
95
// Override with provided Bundle info
94
96
if (null !== $ input ->getArgument ('bundle ' )) {
95
97
try {
96
98
$ foundBundle = $ kernel ->getBundle ($ input ->getArgument ('bundle ' ));
97
- $ rootPath = $ foundBundle ->getPath ();
99
+ $ transPaths = array (
100
+ $ foundBundle ->getPath ().'/Resources/ ' ,
101
+ sprintf ('%s/Resources/%s/ ' , $ kernel ->getRootDir (), $ foundBundle ->getName ()),
102
+ );
98
103
$ currentName = $ foundBundle ->getName ();
99
104
} catch (\InvalidArgumentException $ e ) {
100
105
// such a bundle does not exist, so treat the argument as path
101
- $ rootPath = $ input ->getArgument ('bundle ' );
102
- $ currentName = $ rootPath ;
106
+ $ transPaths = array ( $ input ->getArgument ('bundle ' ). ' /Resources/ ' );
107
+ $ currentName = $ transPaths [ 0 ] ;
103
108
104
- if (!is_dir ($ rootPath )) {
105
- throw new \InvalidArgumentException (sprintf ('<error>"%s" is neither an enabled bundle nor a directory.</error> ' , $ rootPath ));
109
+ if (!is_dir ($ transPaths [ 0 ] )) {
110
+ throw new \InvalidArgumentException (sprintf ('<error>"%s" is neither an enabled bundle nor a directory.</error> ' , $ transPaths [ 0 ] ));
106
111
}
107
112
}
108
113
}
109
114
110
115
$ output ->title ('Symfony translation update command ' );
111
-
112
- // get bundle directory
113
- $ translationsPath = $ rootPath .'/Resources/translations ' ;
114
116
$ output ->text (sprintf ('Generating "<info>%s</info>" translation files for "<info>%s</info>" ' , $ input ->getArgument ('locale ' ), $ currentName ));
115
117
116
118
// load any messages from templates
117
119
$ extractedCatalogue = new MessageCatalogue ($ input ->getArgument ('locale ' ));
118
120
$ output ->text ('Parsing templates ' );
119
121
$ extractor = $ this ->getContainer ()->get ('translation.extractor ' );
120
122
$ extractor ->setPrefix ($ input ->getOption ('prefix ' ));
121
- $ extractor ->extract ($ rootPath .'/Resources/views/ ' , $ extractedCatalogue );
123
+ foreach ($ transPaths as $ path ) {
124
+ $ path = $ path .'views ' ;
125
+ if (is_dir ($ path )) {
126
+ $ extractor ->extract ($ path , $ extractedCatalogue );
127
+ }
128
+ }
122
129
123
130
// load any existing messages from the translation files
124
131
$ currentCatalogue = new MessageCatalogue ($ input ->getArgument ('locale ' ));
125
132
$ output ->text ('Loading translation files ' );
126
133
$ loader = $ this ->getContainer ()->get ('translation.loader ' );
127
- $ loader ->loadMessages ($ translationsPath , $ currentCatalogue );
134
+ foreach ($ transPaths as $ path ) {
135
+ $ path = $ path .'translations ' ;
136
+ if (is_dir ($ path )) {
137
+ $ loader ->loadMessages ($ path , $ currentCatalogue );
138
+ }
139
+ }
128
140
129
141
// process catalogues
130
142
$ operation = $ input ->getOption ('clean ' )
@@ -150,7 +162,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
150
162
array_map (function ($ id ) {
151
163
return sprintf ('<fg=green>%s</> ' , $ id );
152
164
}, $ newKeys ),
153
- array_map (function ($ id ) {
165
+ array_map (function ($ id ) {
154
166
return sprintf ('<fg=red>%s</> ' , $ id );
155
167
}, array_keys ($ operation ->getObsoleteMessages ($ domain )))
156
168
));
@@ -168,7 +180,18 @@ protected function execute(InputInterface $input, OutputInterface $output)
168
180
// save the files
169
181
if ($ input ->getOption ('force ' ) === true ) {
170
182
$ output ->text ('Writing files ' );
171
- $ writer ->writeTranslations ($ operation ->getResult (), $ input ->getOption ('output-format ' ), array ('path ' => $ translationsPath , 'default_locale ' => $ this ->getContainer ()->getParameter ('kernel.default_locale ' )));
183
+
184
+ $ bundleTransPath = false ;
185
+ foreach ($ transPaths as $ path ) {
186
+ $ path = $ path .'translations ' ;
187
+ if (is_dir ($ path )) {
188
+ $ bundleTransPath = $ path ;
189
+ }
190
+ }
191
+
192
+ if ($ bundleTransPath ) {
193
+ $ writer ->writeTranslations ($ operation ->getResult (), $ input ->getOption ('output-format ' ), array ('path ' => $ bundleTransPath , 'default_locale ' => $ this ->getContainer ()->getParameter ('kernel.default_locale ' )));
194
+ }
172
195
}
173
196
174
197
$ output ->newLine ();
0 commit comments