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