i18nexus-cli 3.3.0 → 3.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/commands/pull.js +35 -10
- package/package.json +1 -1
package/commands/pull.js
CHANGED
|
@@ -61,26 +61,51 @@ const pull = async opt => {
|
|
|
61
61
|
|
|
62
62
|
const usingVersion = opt.version !== 'latest';
|
|
63
63
|
|
|
64
|
-
let url = usingVersion
|
|
65
|
-
? `https://cdn.i18nexus.com/versions/${opt.version}/translations.json`
|
|
66
|
-
: `${baseUrl}/project_resources/translations.json`;
|
|
67
|
-
|
|
68
|
-
url += `?api_key=${opt.apiKey}`;
|
|
69
|
-
|
|
70
64
|
console.log(`Downloading translations to ${path}...`);
|
|
71
65
|
|
|
72
|
-
const
|
|
66
|
+
const lngResponse = await handleFetch(
|
|
67
|
+
`${baseUrl}/project_resources/languages.json?api_key=${opt.apiKey}`
|
|
68
|
+
);
|
|
73
69
|
|
|
74
|
-
if (
|
|
70
|
+
if (lngResponse.status !== 200) {
|
|
75
71
|
return handleError(
|
|
76
|
-
|
|
72
|
+
lngResponse,
|
|
77
73
|
usingVersion
|
|
78
74
|
? 'There was a problem fetching your translations. Please ensure you are using the correct API key and a valid version number.'
|
|
79
75
|
: 'There was a problem fetching your translations. Please try again in a moment.'
|
|
80
76
|
);
|
|
81
77
|
}
|
|
82
78
|
|
|
83
|
-
const
|
|
79
|
+
const languageCodes = (await lngResponse.json()).collection.map(
|
|
80
|
+
lng => lng.full_code
|
|
81
|
+
);
|
|
82
|
+
|
|
83
|
+
const translations = {};
|
|
84
|
+
|
|
85
|
+
for (let index = 0; index < languageCodes.length; index++) {
|
|
86
|
+
const lng = languageCodes[index];
|
|
87
|
+
|
|
88
|
+
let url = usingVersion
|
|
89
|
+
? `https://cdn.i18nexus.com/versions/${opt.version}/translations/${lng}.json`
|
|
90
|
+
: `${baseUrl}/project_resources/translations/${lng}.json`;
|
|
91
|
+
|
|
92
|
+
url += `?api_key=${opt.apiKey}`;
|
|
93
|
+
|
|
94
|
+
const response = await handleFetch(url);
|
|
95
|
+
|
|
96
|
+
if (response.status !== 200) {
|
|
97
|
+
return handleError(
|
|
98
|
+
response,
|
|
99
|
+
usingVersion
|
|
100
|
+
? 'There was a problem fetching your translations. Please ensure you are using the correct API key and a valid version number.'
|
|
101
|
+
: 'There was a problem fetching your translations. Please try again in a moment.'
|
|
102
|
+
);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
const lngTranslations = await response.json();
|
|
106
|
+
|
|
107
|
+
translations[lng] = lngTranslations;
|
|
108
|
+
}
|
|
84
109
|
|
|
85
110
|
if (opt.clean) {
|
|
86
111
|
cleanDirectory(path);
|