@theia/localization-manager 1.56.0 → 1.57.0-next.136
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/README.md +2 -2
- package/lib/deepl-api.d.ts.map +1 -1
- package/lib/deepl-api.js +26 -5
- package/lib/deepl-api.js.map +1 -1
- package/package.json +4 -3
- package/src/deepl-api.ts +26 -5
package/README.md
CHANGED
|
@@ -45,7 +45,6 @@ Additionally, Theia provides a simple way to translate the generated JSON files
|
|
|
45
45
|
}
|
|
46
46
|
```
|
|
47
47
|
|
|
48
|
-
|
|
49
48
|
Only JSON entries without corresponding translations are translated using DeepL. This ensures that manual changes to the translated files aren't overwritten and only new translation entries are actually sent to DeepL.
|
|
50
49
|
|
|
51
50
|
Use `theia nls-localize --help` for more information on how to use the command and supply DeepL API keys.
|
|
@@ -63,5 +62,6 @@ For more information, see the [internationalization documentation](https://theia
|
|
|
63
62
|
- [一 (Secondary) GNU General Public License, version 2 with the GNU Classpath Exception](https://projects.eclipse.org/license/secondary-gpl-2.0-cp)
|
|
64
63
|
|
|
65
64
|
## Trademark
|
|
65
|
+
|
|
66
66
|
"Theia" is a trademark of the Eclipse Foundation
|
|
67
|
-
https://www.eclipse.org/theia
|
|
67
|
+
<https://www.eclipse.org/theia>
|
package/lib/deepl-api.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"deepl-api.d.ts","sourceRoot":"","sources":["../src/deepl-api.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"deepl-api.d.ts","sourceRoot":"","sources":["../src/deepl-api.ts"],"names":[],"mappings":"AA4BA,wBAAsB,KAAK,CACvB,UAAU,EAAE,eAAe,GAC5B,OAAO,CAAC,aAAa,CAAC,CAsBxB;AA4DD,MAAM,MAAM,aAAa,GACnB,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,OAAO,GACP,OAAO,GACP,IAAI,GACJ,IAA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CAAA;CACf"}
|
package/lib/deepl-api.js
CHANGED
|
@@ -17,9 +17,15 @@
|
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
18
|
exports.isSupportedLanguage = exports.defaultLanguages = exports.supportedLanguages = exports.deepl = void 0;
|
|
19
19
|
const bent = require("bent");
|
|
20
|
+
const limiter_1 = require("limiter");
|
|
20
21
|
const post = bent('POST', 'json', 200);
|
|
21
22
|
// 50 is the maximum amount of translations per request
|
|
22
23
|
const deeplLimit = 50;
|
|
24
|
+
const rateLimiter = new limiter_1.RateLimiter({
|
|
25
|
+
tokensPerInterval: 10,
|
|
26
|
+
interval: 'second',
|
|
27
|
+
fireImmediately: true
|
|
28
|
+
});
|
|
23
29
|
async function deepl(parameters) {
|
|
24
30
|
coerceLanguage(parameters);
|
|
25
31
|
const sub_domain = parameters.free_api ? 'api-free' : 'api';
|
|
@@ -28,12 +34,11 @@ async function deepl(parameters) {
|
|
|
28
34
|
while (textArray.length > 0) {
|
|
29
35
|
textChunks.push(textArray.splice(0, deeplLimit));
|
|
30
36
|
}
|
|
31
|
-
const responses = await Promise.all(textChunks.map(chunk => {
|
|
37
|
+
const responses = await Promise.all(textChunks.map(async (chunk) => {
|
|
32
38
|
const parameterCopy = { ...parameters, text: chunk };
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
});
|
|
39
|
+
const url = `https://${sub_domain}.deepl.com/v2/translate`;
|
|
40
|
+
const buffer = Buffer.from(toFormData(parameterCopy));
|
|
41
|
+
return postWithRetry(url, buffer, 1);
|
|
37
42
|
}));
|
|
38
43
|
const mergedResponse = { translations: [] };
|
|
39
44
|
for (const response of responses) {
|
|
@@ -45,6 +50,22 @@ async function deepl(parameters) {
|
|
|
45
50
|
return mergedResponse;
|
|
46
51
|
}
|
|
47
52
|
exports.deepl = deepl;
|
|
53
|
+
async function postWithRetry(url, buffer, attempt) {
|
|
54
|
+
try {
|
|
55
|
+
await rateLimiter.removeTokens(Math.min(attempt, 10));
|
|
56
|
+
const response = await post(url, buffer, {
|
|
57
|
+
'Content-Type': 'application/x-www-form-urlencoded',
|
|
58
|
+
'User-Agent': 'Theia-Localization-Manager'
|
|
59
|
+
});
|
|
60
|
+
return response;
|
|
61
|
+
}
|
|
62
|
+
catch (e) {
|
|
63
|
+
if ('message' in e && typeof e.message === 'string' && e.message.includes('Too Many Requests')) {
|
|
64
|
+
return postWithRetry(url, buffer, attempt + 1);
|
|
65
|
+
}
|
|
66
|
+
throw e;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
48
69
|
/**
|
|
49
70
|
* Coerces the target language into a form expected by Deepl.
|
|
50
71
|
*
|
package/lib/deepl-api.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"deepl-api.js","sourceRoot":"","sources":["../src/deepl-api.ts"],"names":[],"mappings":";AAAA,gFAAgF;AAChF,yCAAyC;AACzC,EAAE;AACF,2EAA2E;AAC3E,mEAAmE;AACnE,wCAAwC;AACxC,EAAE;AACF,4EAA4E;AAC5E,8EAA8E;AAC9E,6EAA6E;AAC7E,yDAAyD;AACzD,uDAAuD;AACvD,EAAE;AACF,gFAAgF;AAChF,gFAAgF;;;AAEhF,6BAA6B;
|
|
1
|
+
{"version":3,"file":"deepl-api.js","sourceRoot":"","sources":["../src/deepl-api.ts"],"names":[],"mappings":";AAAA,gFAAgF;AAChF,yCAAyC;AACzC,EAAE;AACF,2EAA2E;AAC3E,mEAAmE;AACnE,wCAAwC;AACxC,EAAE;AACF,4EAA4E;AAC5E,8EAA8E;AAC9E,6EAA6E;AAC7E,yDAAyD;AACzD,uDAAuD;AACvD,EAAE;AACF,gFAAgF;AAChF,gFAAgF;;;AAEhF,6BAA6B;AAC7B,qCAAsC;AAEtC,MAAM,IAAI,GAAG,IAAI,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,CAAC,CAAC;AACvC,uDAAuD;AACvD,MAAM,UAAU,GAAG,EAAE,CAAC;AACtB,MAAM,WAAW,GAA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IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO;CACzH,CAAC;AAEF,gFAAgF;AACnE,QAAA,gBAAgB,GAAG;IAC5B,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI;CACrF,CAAC;AAEX,SAAgB,mBAAmB,CAAC,QAAgB;IAChD,OAAO,0BAAkB,CAAC,QAAQ,CAAC,QAAQ,CAAC,WAAW,EAAE,CAAC,CAAC;AAC/D,CAAC;AAFD,kDAEC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@theia/localization-manager",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.57.0-next.136+9a2072774",
|
|
4
4
|
"description": "Theia localization manager API.",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -36,14 +36,15 @@
|
|
|
36
36
|
"deepmerge": "^4.2.2",
|
|
37
37
|
"fs-extra": "^4.0.2",
|
|
38
38
|
"glob": "^7.2.0",
|
|
39
|
+
"limiter": "^2.1.0",
|
|
39
40
|
"tslib": "^2.6.2",
|
|
40
41
|
"typescript": "~5.4.5"
|
|
41
42
|
},
|
|
42
43
|
"devDependencies": {
|
|
43
|
-
"@theia/ext-scripts": "1.
|
|
44
|
+
"@theia/ext-scripts": "1.58.0"
|
|
44
45
|
},
|
|
45
46
|
"nyc": {
|
|
46
47
|
"extends": "../../configs/nyc.json"
|
|
47
48
|
},
|
|
48
|
-
"gitHead": "
|
|
49
|
+
"gitHead": "9a20727743172a4efa46334f4136a1242b160848"
|
|
49
50
|
}
|
package/src/deepl-api.ts
CHANGED
|
@@ -15,10 +15,16 @@
|
|
|
15
15
|
// *****************************************************************************
|
|
16
16
|
|
|
17
17
|
import * as bent from 'bent';
|
|
18
|
+
import { RateLimiter } from 'limiter';
|
|
18
19
|
|
|
19
20
|
const post = bent('POST', 'json', 200);
|
|
20
21
|
// 50 is the maximum amount of translations per request
|
|
21
22
|
const deeplLimit = 50;
|
|
23
|
+
const rateLimiter = new RateLimiter({
|
|
24
|
+
tokensPerInterval: 10,
|
|
25
|
+
interval: 'second',
|
|
26
|
+
fireImmediately: true
|
|
27
|
+
});
|
|
22
28
|
|
|
23
29
|
export async function deepl(
|
|
24
30
|
parameters: DeeplParameters
|
|
@@ -30,12 +36,11 @@ export async function deepl(
|
|
|
30
36
|
while (textArray.length > 0) {
|
|
31
37
|
textChunks.push(textArray.splice(0, deeplLimit));
|
|
32
38
|
}
|
|
33
|
-
const responses: DeeplResponse[] = await Promise.all(textChunks.map(chunk => {
|
|
39
|
+
const responses: DeeplResponse[] = await Promise.all(textChunks.map(async chunk => {
|
|
34
40
|
const parameterCopy: DeeplParameters = { ...parameters, text: chunk };
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
});
|
|
41
|
+
const url = `https://${sub_domain}.deepl.com/v2/translate`;
|
|
42
|
+
const buffer = Buffer.from(toFormData(parameterCopy));
|
|
43
|
+
return postWithRetry(url, buffer, 1);
|
|
39
44
|
}));
|
|
40
45
|
const mergedResponse: DeeplResponse = { translations: [] };
|
|
41
46
|
for (const response of responses) {
|
|
@@ -47,6 +52,22 @@ export async function deepl(
|
|
|
47
52
|
return mergedResponse;
|
|
48
53
|
}
|
|
49
54
|
|
|
55
|
+
async function postWithRetry(url: string, buffer: Buffer, attempt: number): Promise<DeeplResponse> {
|
|
56
|
+
try {
|
|
57
|
+
await rateLimiter.removeTokens(Math.min(attempt, 10));
|
|
58
|
+
const response = await post(url, buffer, {
|
|
59
|
+
'Content-Type': 'application/x-www-form-urlencoded',
|
|
60
|
+
'User-Agent': 'Theia-Localization-Manager'
|
|
61
|
+
});
|
|
62
|
+
return response;
|
|
63
|
+
} catch (e) {
|
|
64
|
+
if ('message' in e && typeof e.message === 'string' && e.message.includes('Too Many Requests')) {
|
|
65
|
+
return postWithRetry(url, buffer, attempt + 1);
|
|
66
|
+
}
|
|
67
|
+
throw e;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
50
71
|
/**
|
|
51
72
|
* Coerces the target language into a form expected by Deepl.
|
|
52
73
|
*
|