@@ -64,6 +64,11 @@ class PhraseApp implements LoggerAwareInterface
64
64
*/
65
65
private $ downloadedLocales = [];
66
66
67
+ /**
68
+ * @var array
69
+ */
70
+ private $ tagCache = [];
71
+
67
72
/**
68
73
* @var LoggerInterface
69
74
*/
@@ -108,6 +113,11 @@ public function __construct(PhraseAppClient $client, TranslationLoader $translat
108
113
$ this ->fileMerger = $ fileMerger ;
109
114
}
110
115
116
+ public function __destruct ()
117
+ {
118
+ $ this ->cleanUp ();
119
+ }
120
+
111
121
/**
112
122
* Sets a logger instance on the object.
113
123
*
@@ -151,26 +161,9 @@ public function getLocales()
151
161
*/
152
162
protected function downloadLocale ($ targetLocale )
153
163
{
164
+
154
165
$ sourceLocale = $ this ->locales [$ targetLocale ];
155
166
156
- if (true === array_key_exists ($ sourceLocale , $ this ->downloadedLocales )) {
157
- $ this ->logger ->notice ('Copying translations for locale "{targetLocale}" from "{sourceLocale}". ' , [
158
- 'targetLocale ' => $ targetLocale ,
159
- 'sourceLocale ' => $ sourceLocale
160
- ]);
161
-
162
- foreach ($ this ->catalogues as $ catalogueName => $ catalogueConfig ) {
163
- $ extension = $ catalogueConfig ['output_format ' ];
164
-
165
- $ tmpFile = sprintf ('%s/%s.%s.%s ' , $ this ->getTmpPath (), $ catalogueName , $ targetLocale , $ extension );
166
-
167
- // Make copy because operated catalogues must belong to the same locale
168
- copy ($ this ->downloadedLocales [$ sourceLocale ][$ catalogueName ], $ tmpFile );
169
- }
170
-
171
- return $ this ->downloadedLocales [$ sourceLocale ];
172
- }
173
-
174
167
$ this ->logger ->notice ('Downloading translations for locale "{targetLocale}" from "{sourceLocale}". ' , [
175
168
'targetLocale ' => $ targetLocale ,
176
169
'sourceLocale ' => $ sourceLocale
@@ -229,14 +222,22 @@ protected function downloadLocale($targetLocale)
229
222
*/
230
223
protected function makeDownloadRequest ($ locale , $ format , $ tag )
231
224
{
225
+ if (array_key_exists ($ locale , $ this ->tagCache ) && array_key_exists ($ tag , $ this ->tagCache [$ locale ])) {
226
+ return $ this ->tagCache [$ locale ][$ tag ];
227
+ }
228
+
232
229
$ response = $ this ->client ->request ('locale.download ' , [
233
230
'project_id ' => $ this ->projectId ,
234
231
'id ' => $ locale ,
235
232
'file_format ' => $ format ,
236
233
'tag ' => $ tag ,
237
234
]);
238
235
239
- return $ response ['text ' ]->getContents ();
236
+ $ content = $ response ['text ' ]->getContents ();
237
+
238
+ $ this ->tagCache [$ locale ][$ tag ] = $ content ;
239
+
240
+ return $ content ;
240
241
}
241
242
242
243
/**
@@ -270,8 +271,6 @@ public function process(array $locales)
270
271
$ this ->downloadLocale ($ locale );
271
272
$ this ->dumpMessages ($ locale );
272
273
}
273
-
274
- $ this ->cleanUp ();
275
274
}
276
275
277
276
/**
0 commit comments