1616use Symfony \Component \Console \Input \InputInterface ;
1717use Symfony \Component \Console \Input \InputOption ;
1818use Symfony \Component \Console \Output \OutputInterface ;
19+ use Symfony \Component \Console \Style \SymfonyStyle ;
1920use Symfony \Component \Finder \Finder ;
21+ use Translation \Bundle \Catalogue \CatalogueWriter ;
2022use Translation \Bundle \Service \CacheClearer ;
2123use Translation \Bundle \Service \ConfigurationManager ;
2224use Translation \Bundle \Service \StorageManager ;
@@ -31,24 +33,21 @@ class DownloadCommand extends Command
3133
3234 protected static $ defaultName = 'translation:download ' ;
3335
34- /**
35- * @var ConfigurationManager
36- */
3736 private $ configurationManager ;
38-
39- /**
40- * @var CacheClearer
41- */
4237 private $ cacheCleaner ;
38+ private $ catalogueWriter ;
4339
4440 public function __construct (
4541 StorageManager $ storageManager ,
4642 ConfigurationManager $ configurationManager ,
47- CacheClearer $ cacheCleaner
43+ CacheClearer $ cacheCleaner ,
44+ CatalogueWriter $ catalogueWriter
4845 ) {
4946 $ this ->storageManager = $ storageManager ;
5047 $ this ->configurationManager = $ configurationManager ;
5148 $ this ->cacheCleaner = $ cacheCleaner ;
49+ $ this ->catalogueWriter = $ catalogueWriter ;
50+
5251 parent ::__construct ();
5352 }
5453
@@ -57,31 +56,55 @@ protected function configure(): void
5756 $ this
5857 ->setName (self ::$ defaultName )
5958 ->setDescription ('Replace local messages with messages from remote ' )
59+ ->setHelp (<<<EOT
60+ The <info>%command.name%</info> will erase all your local translations and replace them with translations downloaded from the remote.
61+ EOT
62+ )
6063 ->addArgument ('configuration ' , InputArgument::OPTIONAL , 'The configuration to use ' , 'default ' )
61- ->addOption ('cache ' , null , InputOption::VALUE_NONE , 'Clear the cache if the translations have changed ' )
64+ ->addOption ('cache ' , null , InputOption::VALUE_NONE , '[DEPRECATED] Cache is now automatically cleared when translations have changed. ' )
6265 ->addOption ('bundle ' , 'b ' , InputOption::VALUE_REQUIRED , 'The bundle you want update translations from. ' )
6366 ;
6467 }
6568
6669 protected function execute (InputInterface $ input , OutputInterface $ output ): int
6770 {
71+ $ io = new SymfonyStyle ($ input , $ output );
72+
73+ if ($ input ->getOption ('cache ' )) {
74+ $ message = 'The --cache option is deprecated as it \'s now the default behaviour of this command. ' ;
75+
76+ $ io ->note ($ message );
77+ @\trigger_error ($ message , E_USER_DEPRECATED );
78+ }
79+
6880 $ configName = $ input ->getArgument ('configuration ' );
6981 $ config = $ this ->configurationManager ->getConfiguration ($ configName );
7082 $ storage = $ this ->getStorage ($ configName );
7183
7284 $ this ->configureBundleDirs ($ input , $ config );
7385
74- if ( $ input -> getOption ( ' cache ' )) {
75- $ translationsDirectory = $ config -> getOutputDir ( );
76- $ md5BeforeDownload = $ this -> hashDirectory ( $ translationsDirectory );
77- $ storage ->download ();
78- $ md5AfterDownload = $ this ->hashDirectory ( $ translationsDirectory );
86+ $ translationsDirectory = $ config -> getOutputDir ();
87+ $ md5BeforeDownload = $ this -> hashDirectory ( $ translationsDirectory );
88+
89+ $ catalogues = $ storage ->download ();
90+ $ this ->catalogueWriter -> writeCatalogues ( $ config , $ catalogues );
7991
80- if ($ md5BeforeDownload !== $ md5AfterDownload ) {
81- $ this ->cacheCleaner ->clearAndWarmUp ();
92+ $ translationsCount = 0 ;
93+ foreach ($ catalogues as $ locale => $ catalogue ) {
94+ foreach ($ catalogue ->all () as $ domain => $ messages ) {
95+ $ translationsCount += \count ($ messages );
8296 }
97+ }
98+
99+ $ io ->text ("<info> $ translationsCount</info> translations have been downloaded. " );
100+
101+ $ md5AfterDownload = $ this ->hashDirectory ($ translationsDirectory );
102+
103+ if ($ md5BeforeDownload !== $ md5AfterDownload ) {
104+ $ io ->success ('Translations updated successfully! ' );
105+ $ this ->cacheCleaner ->clearAndWarmUp ();
83106 } else {
84- $ storage -> download ( );
107+ $ io -> success ( ' All translations were up to date. ' );
85108 }
86109
87110 return 0 ;
0 commit comments