@@ -90,47 +90,37 @@ public function read(array $domains, array $locales): TranslatorBag
90
90
{
91
91
$ domains = $ domains ?: ['* ' ];
92
92
$ translatorBag = new TranslatorBag ();
93
- $ responses = [];
94
93
95
94
foreach ($ locales as $ locale ) {
96
95
foreach ($ domains as $ domain ) {
97
- $ responses [] = [
98
- 'response ' => $ this ->client ->request ('GET ' , sprintf ('export/locale/%s.xlf ' , rawurlencode ($ locale )), [
99
- 'query ' => [
100
- 'filter ' => $ domain ,
101
- 'status ' => 'translated ' ,
102
- ],
103
- ]),
104
- 'locale ' => $ locale ,
105
- 'domain ' => $ domain ,
106
- ];
107
- }
108
- }
109
-
110
- foreach ($ responses as $ response ) {
111
- $ locale = $ response ['locale ' ];
112
- $ domain = $ response ['domain ' ];
113
- $ response = $ response ['response ' ];
96
+ // Loco forbids concurrent requests, so the requests must be synchronous in order to prevent "429 Too Many Requests" errors.
97
+ $ response = $ this ->client ->request ('GET ' , sprintf ('export/locale/%s.xlf ' , rawurlencode ($ locale )), [
98
+ 'query ' => [
99
+ 'filter ' => $ domain ,
100
+ 'status ' => 'translated ' ,
101
+ ],
102
+ ]);
103
+
104
+ if (404 === $ response ->getStatusCode ()) {
105
+ $ this ->logger ->warning (sprintf ('Locale "%s" for domain "%s" does not exist in Loco. ' , $ locale , $ domain ));
106
+ continue ;
107
+ }
114
108
115
- if (404 === $ response ->getStatusCode ()) {
116
- $ this ->logger ->warning (sprintf ('Locale "%s" for domain "%s" does not exist in Loco. ' , $ locale , $ domain ));
117
- continue ;
118
- }
109
+ $ responseContent = $ response ->getContent (false );
119
110
120
- $ responseContent = $ response ->getContent (false );
111
+ if (200 !== $ response ->getStatusCode ()) {
112
+ throw new ProviderException ('Unable to read the Loco response: ' .$ responseContent , $ response );
113
+ }
121
114
122
- if (200 !== $ response ->getStatusCode ()) {
123
- throw new ProviderException ('Unable to read the Loco response: ' .$ responseContent , $ response );
124
- }
115
+ $ locoCatalogue = $ this ->loader ->load ($ responseContent , $ locale , $ domain );
116
+ $ catalogue = new MessageCatalogue ($ locale );
125
117
126
- $ locoCatalogue = $ this ->loader ->load ($ responseContent , $ locale , $ domain );
127
- $ catalogue = new MessageCatalogue ($ locale );
118
+ foreach ($ locoCatalogue ->all ($ domain ) as $ key => $ message ) {
119
+ $ catalogue ->set ($ this ->retrieveKeyFromId ($ key , $ domain ), $ message , $ domain );
120
+ }
128
121
129
- foreach ($ locoCatalogue ->all ($ domain ) as $ key => $ message ) {
130
- $ catalogue ->set ($ this ->retrieveKeyFromId ($ key , $ domain ), $ message , $ domain );
122
+ $ translatorBag ->addCatalogue ($ catalogue );
131
123
}
132
-
133
- $ translatorBag ->addCatalogue ($ catalogue );
134
124
}
135
125
136
126
return $ translatorBag ;
0 commit comments