@@ -34,14 +34,24 @@ function getResourceLinks(elem) {
34
34
) ;
35
35
}
36
36
37
- async function generateContext ( locale , resourceIds ) {
37
+ async function fetchResource ( locale , id ) {
38
+ const url = id . replace ( "{locale}" , locale ) ;
39
+ const response = await fetch ( url ) ;
40
+ return response . text ( ) ;
41
+ }
42
+
43
+ async function createContext ( locale , resourceIds ) {
38
44
const ctx = new MessageContext ( [ locale ] ) ;
39
- await Promise . all ( resourceIds . map ( resourceId => {
40
- const url = resourceId . replace ( "{locale}" , locale ) ;
41
- return fetch ( url )
42
- . then ( d => d . text ( ) )
43
- . then ( source => ctx . addMessages ( source ) ) ;
44
- } ) ) ;
45
+
46
+ // First fetch all resources
47
+ const resources = await Promise . all (
48
+ resourceIds . map ( id => fetchResource ( locale , id ) )
49
+ ) ;
50
+
51
+ // Then apply them preserving order
52
+ for ( const resource of resources ) {
53
+ ctx . addMessages ( resource ) ;
54
+ }
45
55
return ctx ;
46
56
}
47
57
@@ -56,7 +66,7 @@ function* generateMessages(resourceIds) {
56
66
}
57
67
) ;
58
68
for ( const locale of locales ) {
59
- yield generateContext ( locale , resourceIds ) ;
69
+ yield createContext ( locale , resourceIds ) ;
60
70
}
61
71
}
62
72
0 commit comments