auto-translate-json-library 1.5.1 → 1.5.2
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/build/package.json +1 -1
- package/build/src/azure.js +41 -23
- package/build/src/deepl.js +2 -0
- package/package.json +1 -1
package/build/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "auto-translate-json-library",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.2",
|
|
4
4
|
"description": "Automatically translates JSON language files to other languages using Google Translate,AWS,Azure,DeepL,OpenAI or local OpenAI compatible server",
|
|
5
5
|
"main": "./build/src/index.js",
|
|
6
6
|
"bin": {
|
package/build/src/azure.js
CHANGED
|
@@ -129,32 +129,50 @@ class AzureTranslate {
|
|
|
129
129
|
}
|
|
130
130
|
translateText(text, sourceLocale, targetLocale) {
|
|
131
131
|
return __awaiter(this, void 0, void 0, function* () {
|
|
132
|
+
var _a;
|
|
132
133
|
let args;
|
|
133
134
|
({ args, text } = util_1.Util.replaceContextVariables(text));
|
|
134
135
|
let result = "";
|
|
135
|
-
const
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
136
|
+
const maxRetries = 5;
|
|
137
|
+
let retryCount = 0;
|
|
138
|
+
while (retryCount <= maxRetries) {
|
|
139
|
+
try {
|
|
140
|
+
const response = yield axios({
|
|
141
|
+
baseURL: this.endpoint,
|
|
142
|
+
url: "/translate",
|
|
143
|
+
method: "post",
|
|
144
|
+
headers: {
|
|
145
|
+
"Ocp-Apim-Subscription-Key": this.subscriptionKey,
|
|
146
|
+
"Ocp-Apim-Subscription-Region": this.subscriptionRegion,
|
|
147
|
+
"Content-type": "application/json",
|
|
148
|
+
"X-ClientTraceId": uuidv4().toString(),
|
|
149
|
+
},
|
|
150
|
+
params: {
|
|
151
|
+
"api-version": "3.0",
|
|
152
|
+
from: sourceLocale,
|
|
153
|
+
to: [targetLocale],
|
|
154
|
+
},
|
|
155
|
+
data: [
|
|
156
|
+
{
|
|
157
|
+
text: text,
|
|
158
|
+
},
|
|
159
|
+
],
|
|
160
|
+
responseType: "json",
|
|
161
|
+
});
|
|
162
|
+
result = response.data[0].translations[0].text;
|
|
163
|
+
break; // Success, exit the retry loop
|
|
164
|
+
}
|
|
165
|
+
catch (error) {
|
|
166
|
+
if (((_a = error.response) === null || _a === void 0 ? void 0 : _a.status) === 429 && retryCount < maxRetries) {
|
|
167
|
+
retryCount++;
|
|
168
|
+
console.log(`Rate limit exceeded. Retrying in 10 seconds... (Attempt ${retryCount}/${maxRetries})`);
|
|
169
|
+
yield new Promise(resolve => setTimeout(resolve, 10000)); // Wait 10 second
|
|
170
|
+
}
|
|
171
|
+
else {
|
|
172
|
+
throw error; // Re-throw if it's not a 429 error or we've exceeded max retries
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
}
|
|
158
176
|
result = util_1.Util.replaceArgumentsWithNumbers(args, result);
|
|
159
177
|
return result;
|
|
160
178
|
});
|
package/build/src/deepl.js
CHANGED
|
@@ -101,6 +101,8 @@ class DeepLTranslate {
|
|
|
101
101
|
let result = "";
|
|
102
102
|
const translator = new deepl.Translator(this.subscriptionKey, {
|
|
103
103
|
serverUrl: this.endpoint,
|
|
104
|
+
minTimeout: 10000,
|
|
105
|
+
maxRetries: 5,
|
|
104
106
|
});
|
|
105
107
|
const translation = yield translator.translateText(text, sourceLocale, targetLocale);
|
|
106
108
|
result = translation.text;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "auto-translate-json-library",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.2",
|
|
4
4
|
"description": "Automatically translates JSON language files to other languages using Google Translate,AWS,Azure,DeepL,OpenAI or local OpenAI compatible server",
|
|
5
5
|
"main": "./build/src/index.js",
|
|
6
6
|
"bin": {
|