@@ -46,14 +46,18 @@ class TranslationDebugCommand extends Command
4646 private $ translator ;
4747 private $ reader ;
4848 private $ extractor ;
49+ private $ defaultTransPath ;
50+ private $ defaultViewsPath ;
4951
50- public function __construct (TranslatorInterface $ translator , TranslationReaderInterface $ reader , ExtractorInterface $ extractor )
52+ public function __construct (TranslatorInterface $ translator , TranslationReaderInterface $ reader , ExtractorInterface $ extractor, string $ defaultTransPath = null , string $ defaultViewsPath = null )
5153 {
5254 parent ::__construct ();
5355
5456 $ this ->translator = $ translator ;
5557 $ this ->reader = $ reader ;
5658 $ this ->extractor = $ extractor ;
59+ $ this ->defaultTransPath = $ defaultTransPath ;
60+ $ this ->defaultViewsPath = $ defaultViewsPath ;
5761 }
5862
5963 /**
@@ -117,34 +121,56 @@ protected function execute(InputInterface $input, OutputInterface $output)
117121 /** @var KernelInterface $kernel */
118122 $ kernel = $ this ->getApplication ()->getKernel ();
119123
120- // Define Root Path to App folder
121- $ transPaths = array ($ kernel ->getRootDir ().'/Resources/ ' );
124+ // Define Root Paths
125+ $ transPaths = array ($ kernel ->getRootDir ().'/Resources/translations ' );
126+ if ($ this ->defaultTransPath ) {
127+ $ transPaths [] = $ this ->defaultTransPath ;
128+ }
129+ $ viewsPaths = array ($ kernel ->getRootDir ().'/Resources/views ' );
130+ if ($ this ->defaultViewsPath ) {
131+ $ viewsPaths [] = $ this ->defaultViewsPath ;
132+ }
122133
123134 // Override with provided Bundle info
124135 if (null !== $ input ->getArgument ('bundle ' )) {
125136 try {
126137 $ bundle = $ kernel ->getBundle ($ input ->getArgument ('bundle ' ));
127- $ transPaths = array (
128- $ bundle ->getPath ().'/Resources/ ' ,
129- sprintf ('%s/Resources/%s/ ' , $ kernel ->getRootDir (), $ bundle ->getName ()),
130- );
138+ $ transPaths = array ($ bundle ->getPath ().'/Resources/translations ' );
139+ if ($ this ->defaultTransPath ) {
140+ $ transPaths [] = $ this ->defaultTransPath .'/ ' .$ bundle ->getName ();
141+ }
142+ $ transPaths [] = sprintf ('%s/Resources/%s/translations ' , $ kernel ->getRootDir (), $ bundle ->getName ());
143+ $ viewsPaths = array ($ bundle ->getPath ().'/Resources/views ' );
144+ if ($ this ->defaultViewsPath ) {
145+ $ viewsPaths [] = $ this ->defaultViewsPath .'/bundles/ ' .$ bundle ->getName ();
146+ }
147+ $ viewsPaths [] = sprintf ('%s/Resources/%s/views ' , $ kernel ->getRootDir (), $ bundle ->getName ());
131148 } catch (\InvalidArgumentException $ e ) {
132149 // such a bundle does not exist, so treat the argument as path
133- $ transPaths = array ($ input ->getArgument ('bundle ' ).'/Resources/ ' );
150+ $ transPaths = array ($ input ->getArgument ('bundle ' ).'/Resources/translations ' );
151+ $ viewsPaths = array ($ input ->getArgument ('bundle ' ).'/Resources/views ' );
134152
135153 if (!is_dir ($ transPaths [0 ])) {
136154 throw new \InvalidArgumentException (sprintf ('"%s" is neither an enabled bundle nor a directory. ' , $ transPaths [0 ]));
137155 }
138156 }
139157 } elseif ($ input ->getOption ('all ' )) {
140158 foreach ($ kernel ->getBundles () as $ bundle ) {
141- $ transPaths [] = $ bundle ->getPath ().'/Resources/ ' ;
142- $ transPaths [] = sprintf ('%s/Resources/%s/ ' , $ kernel ->getRootDir (), $ bundle ->getName ());
159+ $ transPaths [] = $ bundle ->getPath ().'/Resources/translations ' ;
160+ if ($ this ->defaultTransPath ) {
161+ $ transPaths [] = $ this ->defaultTransPath .'/ ' .$ bundle ->getName ();
162+ }
163+ $ transPaths [] = sprintf ('%s/Resources/%s/translations ' , $ kernel ->getRootDir (), $ bundle ->getName ());
164+ $ viewsPaths [] = $ bundle ->getPath ().'/Resources/views ' ;
165+ if ($ this ->defaultViewsPath ) {
166+ $ viewsPaths [] = $ this ->defaultViewsPath .'/bundles/ ' .$ bundle ->getName ();
167+ }
168+ $ viewsPaths [] = sprintf ('%s/Resources/%s/views ' , $ kernel ->getRootDir (), $ bundle ->getName ());
143169 }
144170 }
145171
146172 // Extract used messages
147- $ extractedCatalogue = $ this ->extractMessages ($ locale , $ transPaths );
173+ $ extractedCatalogue = $ this ->extractMessages ($ locale , $ viewsPaths );
148174
149175 // Load defined messages
150176 $ currentCatalogue = $ this ->loadCurrentMessages ($ locale , $ transPaths );
@@ -268,7 +294,6 @@ private function extractMessages(string $locale, array $transPaths): MessageCata
268294 {
269295 $ extractedCatalogue = new MessageCatalogue ($ locale );
270296 foreach ($ transPaths as $ path ) {
271- $ path = $ path .'views ' ;
272297 if (is_dir ($ path )) {
273298 $ this ->extractor ->extract ($ path , $ extractedCatalogue );
274299 }
@@ -281,7 +306,6 @@ private function loadCurrentMessages(string $locale, array $transPaths): Message
281306 {
282307 $ currentCatalogue = new MessageCatalogue ($ locale );
283308 foreach ($ transPaths as $ path ) {
284- $ path = $ path .'translations ' ;
285309 if (is_dir ($ path )) {
286310 $ this ->reader ->read ($ path , $ currentCatalogue );
287311 }
@@ -304,7 +328,6 @@ private function loadFallbackCatalogues(string $locale, array $transPaths): arra
304328
305329 $ fallbackCatalogue = new MessageCatalogue ($ fallbackLocale );
306330 foreach ($ transPaths as $ path ) {
307- $ path = $ path .'translations ' ;
308331 if (is_dir ($ path )) {
309332 $ this ->reader ->read ($ path , $ fallbackCatalogue );
310333 }
0 commit comments