generaltranslation 1.2.14 → 1.2.15
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/index.js +2 -2
- package/package.json +1 -1
- package/translate/translate.js +14 -5
package/index.js
CHANGED
|
@@ -50,7 +50,7 @@ class GT {
|
|
|
50
50
|
}
|
|
51
51
|
|
|
52
52
|
// String translation
|
|
53
|
-
async translate(content, language,
|
|
53
|
+
async translate(content, language, ...options) {
|
|
54
54
|
return await _translate({
|
|
55
55
|
content: content, language: language, config: this, ...options,
|
|
56
56
|
});
|
|
@@ -58,7 +58,7 @@ class GT {
|
|
|
58
58
|
|
|
59
59
|
// String translation, of an array of strings
|
|
60
60
|
// requestArray looks like { content: '', language: '' }
|
|
61
|
-
async translateMany(contentArray, language,
|
|
61
|
+
async translateMany(contentArray, language, ...options) {
|
|
62
62
|
return await _translateMany({
|
|
63
63
|
contentArray, language, config: this, ...options
|
|
64
64
|
});
|
package/package.json
CHANGED
package/translate/translate.js
CHANGED
|
@@ -127,6 +127,11 @@ const _translateMany = async ({
|
|
|
127
127
|
throw new Error('Missing API Key!')
|
|
128
128
|
};
|
|
129
129
|
|
|
130
|
+
const defaultLanguage = config?.defaultLanguage;
|
|
131
|
+
if (language === defaultLanguage) {
|
|
132
|
+
return constructAll(contentArray);
|
|
133
|
+
};
|
|
134
|
+
|
|
130
135
|
/*
|
|
131
136
|
// [{content, language,...options}], config
|
|
132
137
|
->
|
|
@@ -138,12 +143,12 @@ const _translateMany = async ({
|
|
|
138
143
|
}]
|
|
139
144
|
*/
|
|
140
145
|
|
|
141
|
-
const
|
|
146
|
+
const processedArray = [];
|
|
142
147
|
const untranslatedArray = [];
|
|
143
148
|
|
|
144
149
|
for (const item of contentArray) {
|
|
145
150
|
const { processed, untranslated } = _processContent({ content: item });
|
|
146
|
-
|
|
151
|
+
processedArray.push(processed);
|
|
147
152
|
untranslatedArray.push(untranslated);
|
|
148
153
|
}
|
|
149
154
|
|
|
@@ -155,19 +160,23 @@ const _translateMany = async ({
|
|
|
155
160
|
'gtx-api-key': apiKey,
|
|
156
161
|
},
|
|
157
162
|
body: JSON.stringify({
|
|
158
|
-
|
|
163
|
+
contentArray: processedArray,
|
|
164
|
+
targetLanguage: language,
|
|
165
|
+
defaultLanguage: defaultLanguage,
|
|
166
|
+
options: { ...options }
|
|
159
167
|
})
|
|
160
168
|
})
|
|
161
169
|
if (!response.ok) {
|
|
170
|
+
|
|
162
171
|
const result = await response.text();
|
|
163
172
|
throw new Error(`${result || response.status}`);
|
|
164
173
|
} else {
|
|
165
174
|
const result = await response.json();
|
|
166
|
-
if (!Array.isArray(result
|
|
175
|
+
if (!Array.isArray(result)) {
|
|
167
176
|
throw new Error(`${result || response.status}`);
|
|
168
177
|
}
|
|
169
178
|
const returnArray = [];
|
|
170
|
-
for (const [index, item] of result.
|
|
179
|
+
for (const [index, item] of result.entries()) {
|
|
171
180
|
returnArray.push(_constructContent({content: item, untranslated: untranslatedArray[index] }));
|
|
172
181
|
}
|
|
173
182
|
return returnArray;
|