66
77namespace Magento \Deploy \Model \Deploy ;
88
9- use Magento \Deploy \Model \DeployManager ;
109use Magento \Framework \App \Filesystem \DirectoryList ;
11- use Magento \Framework \App \Utility \Files ;
1210use Magento \Framework \Filesystem ;
1311use Magento \Framework \Filesystem \Directory \WriteInterface ;
1412use Symfony \Component \Console \Output \OutputInterface ;
1513use Magento \Framework \Console \Cli ;
1614use Magento \Deploy \Console \Command \DeployStaticOptionsInterface as Options ;
17- use \Magento \Framework \RequireJs \Config as RequireJsConfig ;
15+ use Magento \Framework \RequireJs \Config as RequireJsConfig ;
16+ use Magento \Framework \Translate \Js \Config as TranslationJsConfig ;
17+ use Magento \Framework \App \ObjectManager ;
18+ use Magento \Deploy \Model \DeployStrategyFactory ;
1819
20+ /**
21+ * To avoid duplication of deploying of all static content per each theme/local, this class uses copying/symlinking
22+ * of default static files to other locales, separately calls deploy for js dictionary per each locale
23+ */
1924class LocaleQuickDeploy implements DeployInterface
2025{
2126 /**
@@ -38,16 +43,42 @@ class LocaleQuickDeploy implements DeployInterface
3843 */
3944 private $ options = [];
4045
46+ /**
47+ * @var TranslationJsConfig
48+ */
49+ private $ translationJsConfig ;
50+
51+ /**
52+ * @var DeployStrategyFactory
53+ */
54+ private $ deployStrategyFactory ;
55+
56+ /**
57+ * @var DeployInterface[]
58+ */
59+ private $ deploys ;
60+
4161 /**
4262 * @param Filesystem $filesystem
4363 * @param OutputInterface $output
4464 * @param array $options
65+ * @param TranslationJsConfig $translationJsConfig
66+ * @param DeployStrategyFactory $deployStrategyFactory
4567 */
46- public function __construct (\Magento \Framework \Filesystem $ filesystem , OutputInterface $ output , $ options = [])
47- {
68+ public function __construct (
69+ Filesystem $ filesystem ,
70+ OutputInterface $ output ,
71+ $ options = [],
72+ TranslationJsConfig $ translationJsConfig = null ,
73+ DeployStrategyFactory $ deployStrategyFactory = null
74+ ) {
4875 $ this ->filesystem = $ filesystem ;
4976 $ this ->output = $ output ;
5077 $ this ->options = $ options ;
78+ $ this ->translationJsConfig = $ translationJsConfig
79+ ?: ObjectManager::getInstance ()->get (TranslationJsConfig::class);
80+ $ this ->deployStrategyFactory = $ deployStrategyFactory
81+ ?: ObjectManager::getInstance ()->get (DeployStrategyFactory::class);
5182 }
5283
5384 /**
@@ -67,13 +98,13 @@ private function getStaticDirectory()
6798 */
6899 public function deploy ($ area , $ themePath , $ locale )
69100 {
70- if (isset ($ this ->options [Options::DRY_RUN ]) && $ this -> options [Options:: DRY_RUN ] ) {
101+ if (! empty ($ this ->options [Options::DRY_RUN ])) {
71102 return Cli::RETURN_SUCCESS ;
72103 }
73104
74105 $ this ->output ->writeln ("=== {$ area } -> {$ themePath } -> {$ locale } === " );
75106
76- if (! isset ($ this ->options [self ::DEPLOY_BASE_LOCALE ])) {
107+ if (empty ($ this ->options [self ::DEPLOY_BASE_LOCALE ])) {
77108 throw new \InvalidArgumentException ('Deploy base locale must be set for Quick Deploy ' );
78109 }
79110 $ processedFiles = 0 ;
@@ -88,7 +119,7 @@ public function deploy($area, $themePath, $locale)
88119 $ this ->deleteLocaleResource ($ newLocalePath );
89120 $ this ->deleteLocaleResource ($ newRequireJsPath );
90121
91- if (isset ($ this ->options [Options::SYMLINK_LOCALE ]) && $ this -> options [Options:: SYMLINK_LOCALE ] ) {
122+ if (! empty ($ this ->options [Options::SYMLINK_LOCALE ])) {
92123 $ this ->getStaticDirectory ()->createSymlink ($ baseLocalePath , $ newLocalePath );
93124 $ this ->getStaticDirectory ()->createSymlink ($ baseRequireJsPath , $ newRequireJsPath );
94125
@@ -98,20 +129,61 @@ public function deploy($area, $themePath, $locale)
98129 $ this ->getStaticDirectory ()->readRecursively ($ baseLocalePath ),
99130 $ this ->getStaticDirectory ()->readRecursively ($ baseRequireJsPath )
100131 );
132+ $ jsDictionaryEnabled = $ this ->translationJsConfig ->dictionaryEnabled ();
101133 foreach ($ localeFiles as $ path ) {
102134 if ($ this ->getStaticDirectory ()->isFile ($ path )) {
103- $ destination = $ this ->replaceLocaleInPath ($ path , $ baseLocale , $ locale );
104- $ this ->getStaticDirectory ()->copyFile ($ path , $ destination );
105- $ processedFiles ++;
135+ if (!$ jsDictionaryEnabled || !$ this ->isJsDictionary ($ path )) {
136+ $ destination = $ this ->replaceLocaleInPath ($ path , $ baseLocale , $ locale );
137+ $ this ->getStaticDirectory ()->copyFile ($ path , $ destination );
138+ $ processedFiles ++;
139+ }
106140 }
107141 }
108142
143+ if ($ jsDictionaryEnabled ) {
144+ $ this ->getDeploy (
145+ DeployStrategyFactory::DEPLOY_STRATEGY_JS_DICTIONARY ,
146+ [
147+ 'output ' => $ this ->output ,
148+ 'translationJsConfig ' => $ this ->translationJsConfig
149+ ]
150+ )
151+ ->deploy ($ area , $ themePath , $ locale );
152+ $ processedFiles ++;
153+ }
154+
109155 $ this ->output ->writeln ("\nSuccessful copied: {$ processedFiles } files; errors: {$ errorAmount }\n--- \n" );
110156 }
111157
112158 return Cli::RETURN_SUCCESS ;
113159 }
114160
161+ /**
162+ * Get deploy strategy according to required strategy
163+ *
164+ * @param string $strategy
165+ * @param array $params
166+ * @return DeployInterface
167+ */
168+ private function getDeploy ($ strategy , $ params )
169+ {
170+ if (empty ($ this ->deploys [$ strategy ])) {
171+ $ this ->deploys [$ strategy ] = $ this ->deployStrategyFactory ->create ($ strategy , $ params );
172+ }
173+ return $ this ->deploys [$ strategy ];
174+ }
175+
176+ /**
177+ * Define if provided path is js dictionary
178+ *
179+ * @param string $path
180+ * @return bool
181+ */
182+ private function isJsDictionary ($ path )
183+ {
184+ return strpos ($ path , $ this ->translationJsConfig ->getDictionaryFileName ()) !== false ;
185+ }
186+
115187 /**
116188 * @param string $path
117189 * @return void
0 commit comments