21
21
use Symfony \Component \Console \Output \ConsoleOutputInterface ;
22
22
use Symfony \Component \Console \Output \OutputInterface ;
23
23
use Symfony \Component \Console \Style \SymfonyStyle ;
24
+ use Symfony \Component \Filesystem \Path ;
24
25
use Symfony \Component \HttpKernel \KernelInterface ;
25
26
use Symfony \Component \Translation \Catalogue \MergeOperation ;
26
27
use Symfony \Component \Translation \Catalogue \TargetOperation ;
@@ -407,6 +408,7 @@ private function extractMessages(string $locale, array $transPaths, string $pref
407
408
{
408
409
$ extractedCatalogue = new MessageCatalogue ($ locale );
409
410
$ this ->extractor ->setPrefix ($ prefix );
411
+ $ transPaths = $ this ->filterDuplicateTransPaths ($ transPaths );
410
412
foreach ($ transPaths as $ path ) {
411
413
if (is_dir ($ path ) || is_file ($ path )) {
412
414
$ this ->extractor ->extract ($ path , $ extractedCatalogue );
@@ -416,6 +418,31 @@ private function extractMessages(string $locale, array $transPaths, string $pref
416
418
return $ extractedCatalogue ;
417
419
}
418
420
421
+ private function filterDuplicateTransPaths (array $ transPaths ): array
422
+ {
423
+ foreach ($ transPaths as $ index => $ path ) {
424
+ if (is_dir ($ path ) || is_file ($ path )) {
425
+ $ transPaths [$ index ] = realpath ($ path );
426
+ }
427
+ }
428
+
429
+ sort ($ transPaths );
430
+
431
+ $ filteredPaths = [];
432
+
433
+ foreach ($ transPaths as $ path ) {
434
+ foreach ($ filteredPaths as $ filteredPath ) {
435
+ if (is_dir ($ filteredPath ) && Path::isBasePath ($ filteredPath , $ path )) {
436
+ continue 2 ;
437
+ }
438
+ }
439
+
440
+ $ filteredPaths [] = $ path ;
441
+ }
442
+
443
+ return $ filteredPaths ;
444
+ }
445
+
419
446
private function loadCurrentMessages (string $ locale , array $ transPaths ): MessageCatalogue
420
447
{
421
448
$ currentCatalogue = new MessageCatalogue ($ locale );
0 commit comments