@@ -67,6 +67,8 @@ protected function configure()
67
67
*/
68
68
protected function execute (InputInterface $ input , OutputInterface $ output )
69
69
{
70
+ $ kernel = $ this ->getContainer ()->get ('kernel ' );
71
+
70
72
// check presence of force or dump-message
71
73
if ($ input ->getOption ('force ' ) !== true && $ input ->getOption ('dump-messages ' ) !== true ) {
72
74
$ output ->writeln ('<info>You must choose one of --force or --dump-messages</info> ' );
@@ -85,32 +87,43 @@ protected function execute(InputInterface $input, OutputInterface $output)
85
87
}
86
88
87
89
// Define Root Path to App folder
88
- $ rootPath = $ this -> getApplication ()-> getKernel ()-> getRootDir ();
89
- $ currentName = " app folder " ;
90
+ $ transPaths = array ( $ kernel -> getRootDir (). ' /Resources/ ' );
91
+ $ currentName = ' app folder ' ;
90
92
91
93
// Override with provided Bundle info
92
94
if (null !== $ input ->getArgument ('bundle ' )) {
93
- $ foundBundle = $ this ->getApplication ()->getKernel ()->getBundle ($ input ->getArgument ('bundle ' ));
94
- $ rootPath = $ foundBundle ->getPath ();
95
+ $ foundBundle = $ kernel ->getBundle ($ input ->getArgument ('bundle ' ));
96
+ $ transPaths = array (
97
+ $ foundBundle ->getPath ().'/Resources/ ' ,
98
+ sprintf ('%s/Resources/%s/ ' , $ kernel ->getRootDir (), $ foundBundle ->getName ()),
99
+ );
95
100
$ currentName = $ foundBundle ->getName ();
96
101
}
97
102
98
- // get bundle directory
99
- $ translationsPath = $ rootPath .'/Resources/translations ' ;
100
103
$ output ->writeln (sprintf ('Generating "<info>%s</info>" translation files for "<info>%s</info>" ' , $ input ->getArgument ('locale ' ), $ currentName ));
101
104
102
105
// load any messages from templates
103
106
$ extractedCatalogue = new MessageCatalogue ($ input ->getArgument ('locale ' ));
104
107
$ output ->writeln ('Parsing templates ' );
105
108
$ extractor = $ this ->getContainer ()->get ('translation.extractor ' );
106
109
$ extractor ->setPrefix ($ input ->getOption ('prefix ' ));
107
- $ extractor ->extract ($ rootPath .'/Resources/views/ ' , $ extractedCatalogue );
110
+ foreach ($ transPaths as $ path ) {
111
+ $ path = $ path .'views ' ;
112
+ if (is_dir ($ path )) {
113
+ $ extractor ->extract ($ path , $ extractedCatalogue );
114
+ }
115
+ }
108
116
109
117
// load any existing messages from the translation files
110
118
$ currentCatalogue = new MessageCatalogue ($ input ->getArgument ('locale ' ));
111
119
$ output ->writeln ('Loading translation files ' );
112
120
$ loader = $ this ->getContainer ()->get ('translation.loader ' );
113
- $ loader ->loadMessages ($ translationsPath , $ currentCatalogue );
121
+ foreach ($ transPaths as $ path ) {
122
+ $ path = $ path .'translations ' ;
123
+ if (is_dir ($ path )) {
124
+ $ loader ->loadMessages ($ path , $ currentCatalogue );
125
+ }
126
+ }
114
127
115
128
// process catalogues
116
129
$ operation = $ input ->getOption ('clean ' )
@@ -153,7 +166,17 @@ protected function execute(InputInterface $input, OutputInterface $output)
153
166
// save the files
154
167
if ($ input ->getOption ('force ' ) === true ) {
155
168
$ output ->writeln ('Writing files ' );
156
- $ writer ->writeTranslations ($ operation ->getResult (), $ input ->getOption ('output-format ' ), array ('path ' => $ translationsPath , 'default_locale ' => $ this ->getContainer ()->getParameter ('kernel.default_locale ' )));
169
+ $ bundleTransPath = false ;
170
+ foreach ($ transPaths as $ path ) {
171
+ $ path = $ path .'translations ' ;
172
+ if (is_dir ($ path )) {
173
+ $ bundleTransPath = $ path ;
174
+ }
175
+ }
176
+
177
+ if ($ bundleTransPath ) {
178
+ $ writer ->writeTranslations ($ operation ->getResult (), $ input ->getOption ('output-format ' ), array ('path ' => $ bundleTransPath ));
179
+ }
157
180
}
158
181
}
159
182
}
0 commit comments