auto-translate-json-library 1.1.5 → 1.2.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/README.MD +124 -0
- package/aws.d.ts +10 -10
- package/aws.js +131 -131
- package/azure.d.ts +9 -9
- package/azure.js +169 -169
- package/config.d.ts +38 -33
- package/config.js +2 -2
- package/deepl.d.ts +9 -9
- package/deepl.js +82 -82
- package/files.d.ts +20 -19
- package/files.js +88 -88
- package/folderFiles.d.ts +13 -12
- package/folderFiles.js +57 -57
- package/google.d.ts +8 -8
- package/google.js +163 -163
- package/index.d.ts +3 -3
- package/index.js +134 -120
- package/lib.d.ts +2 -2
- package/lib.js +170 -162
- package/openai.d.ts +9 -0
- package/openai.js +167 -0
- package/package.json +38 -12
- package/translate.interface.d.ts +7 -4
- package/translate.interface.js +2 -2
- package/util.d.ts +12 -12
- package/util.js +41 -41
package/azure.js
CHANGED
|
@@ -1,169 +1,169 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.AzureTranslate = void 0;
|
|
13
|
-
const util_1 = require("./util");
|
|
14
|
-
const axios = require(
|
|
15
|
-
const { v4: uuidv4 } = require(
|
|
16
|
-
const supportedLanguages = [
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
];
|
|
121
|
-
class AzureTranslate {
|
|
122
|
-
constructor(subscriptionKey, subscriptionRegion) {
|
|
123
|
-
this.subscriptionKey = subscriptionKey;
|
|
124
|
-
this.subscriptionRegion = subscriptionRegion;
|
|
125
|
-
this.endpoint =
|
|
126
|
-
}
|
|
127
|
-
isValidLocale(targetLocale) {
|
|
128
|
-
return supportedLanguages.includes(targetLocale);
|
|
129
|
-
}
|
|
130
|
-
translateText(text, sourceLocale, targetLocale) {
|
|
131
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
132
|
-
let args;
|
|
133
|
-
({ args, text } = util_1.Util.replaceContextVariables(text));
|
|
134
|
-
let result =
|
|
135
|
-
const response = yield axios({
|
|
136
|
-
baseURL: this.endpoint,
|
|
137
|
-
url:
|
|
138
|
-
method:
|
|
139
|
-
headers: {
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
},
|
|
145
|
-
params: {
|
|
146
|
-
|
|
147
|
-
from: sourceLocale,
|
|
148
|
-
to: [targetLocale]
|
|
149
|
-
},
|
|
150
|
-
data: [
|
|
151
|
-
{
|
|
152
|
-
text: text
|
|
153
|
-
}
|
|
154
|
-
],
|
|
155
|
-
responseType:
|
|
156
|
-
});
|
|
157
|
-
result = response.data[0].translations[0].text;
|
|
158
|
-
result = util_1.Util.replaceArgumentsWithNumbers(args, result);
|
|
159
|
-
return result;
|
|
160
|
-
});
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
exports.AzureTranslate = AzureTranslate;
|
|
164
|
-
// https://docs.microsoft.com/en-us/azure/cognitive-services/translator/quickstart-translator?tabs=nodejs#translate-text
|
|
165
|
-
// Add your location, also known as region. The default is global.
|
|
166
|
-
// This is required if using a Cognitive Services resource.
|
|
167
|
-
/*
|
|
168
|
-
|
|
169
|
-
*/
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.AzureTranslate = void 0;
|
|
13
|
+
const util_1 = require("./util");
|
|
14
|
+
const axios = require("axios").default;
|
|
15
|
+
const { v4: uuidv4 } = require("uuid");
|
|
16
|
+
const supportedLanguages = [
|
|
17
|
+
"af",
|
|
18
|
+
"sq",
|
|
19
|
+
"am",
|
|
20
|
+
"ar",
|
|
21
|
+
"hy",
|
|
22
|
+
"as",
|
|
23
|
+
"az",
|
|
24
|
+
"bn",
|
|
25
|
+
"ba",
|
|
26
|
+
"bs",
|
|
27
|
+
"bg",
|
|
28
|
+
"yue",
|
|
29
|
+
"ca",
|
|
30
|
+
"lzh",
|
|
31
|
+
"zh-Hans",
|
|
32
|
+
"zh-Hant",
|
|
33
|
+
"hr",
|
|
34
|
+
"cs",
|
|
35
|
+
"da",
|
|
36
|
+
"prs",
|
|
37
|
+
"dv",
|
|
38
|
+
"nl",
|
|
39
|
+
"en",
|
|
40
|
+
"et",
|
|
41
|
+
"fj",
|
|
42
|
+
"fil",
|
|
43
|
+
"fi",
|
|
44
|
+
"fr",
|
|
45
|
+
"fr-ca",
|
|
46
|
+
"ka",
|
|
47
|
+
"de",
|
|
48
|
+
"el",
|
|
49
|
+
"gu",
|
|
50
|
+
"ht",
|
|
51
|
+
"he",
|
|
52
|
+
"hi",
|
|
53
|
+
"mww",
|
|
54
|
+
"hu",
|
|
55
|
+
"is",
|
|
56
|
+
"id",
|
|
57
|
+
"iu",
|
|
58
|
+
"ga",
|
|
59
|
+
"it",
|
|
60
|
+
"ja",
|
|
61
|
+
"kn",
|
|
62
|
+
"kk",
|
|
63
|
+
"km",
|
|
64
|
+
"tlh-Latn",
|
|
65
|
+
"tlh-Piqd",
|
|
66
|
+
"ko",
|
|
67
|
+
"ku",
|
|
68
|
+
"kmr",
|
|
69
|
+
"ky",
|
|
70
|
+
"lo",
|
|
71
|
+
"lv",
|
|
72
|
+
"lt",
|
|
73
|
+
"mk",
|
|
74
|
+
"mg",
|
|
75
|
+
"ms",
|
|
76
|
+
"ml",
|
|
77
|
+
"mt",
|
|
78
|
+
"mi",
|
|
79
|
+
"mr",
|
|
80
|
+
"mn-Cyrl",
|
|
81
|
+
"mn-Mong",
|
|
82
|
+
"my",
|
|
83
|
+
"ne",
|
|
84
|
+
"nb",
|
|
85
|
+
"or",
|
|
86
|
+
"ps",
|
|
87
|
+
"fa",
|
|
88
|
+
"pl",
|
|
89
|
+
"pt",
|
|
90
|
+
"pt-pt",
|
|
91
|
+
"pa",
|
|
92
|
+
"otq",
|
|
93
|
+
"ro",
|
|
94
|
+
"ru",
|
|
95
|
+
"sm",
|
|
96
|
+
"sr-Cyrl",
|
|
97
|
+
"sr-Latn",
|
|
98
|
+
"sk",
|
|
99
|
+
"sl",
|
|
100
|
+
"es",
|
|
101
|
+
"sw",
|
|
102
|
+
"sv",
|
|
103
|
+
"ty",
|
|
104
|
+
"ta",
|
|
105
|
+
"tt",
|
|
106
|
+
"te",
|
|
107
|
+
"th",
|
|
108
|
+
"bo",
|
|
109
|
+
"ti",
|
|
110
|
+
"to",
|
|
111
|
+
"tr",
|
|
112
|
+
"tk",
|
|
113
|
+
"uk",
|
|
114
|
+
"ur",
|
|
115
|
+
"ug",
|
|
116
|
+
"uz",
|
|
117
|
+
"vi",
|
|
118
|
+
"cy",
|
|
119
|
+
"yua",
|
|
120
|
+
];
|
|
121
|
+
class AzureTranslate {
|
|
122
|
+
constructor(subscriptionKey, subscriptionRegion) {
|
|
123
|
+
this.subscriptionKey = subscriptionKey;
|
|
124
|
+
this.subscriptionRegion = subscriptionRegion;
|
|
125
|
+
this.endpoint = "https://api.cognitive.microsofttranslator.com";
|
|
126
|
+
}
|
|
127
|
+
isValidLocale(targetLocale) {
|
|
128
|
+
return supportedLanguages.includes(targetLocale);
|
|
129
|
+
}
|
|
130
|
+
translateText(text, sourceLocale, targetLocale) {
|
|
131
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
132
|
+
let args;
|
|
133
|
+
({ args, text } = util_1.Util.replaceContextVariables(text));
|
|
134
|
+
let result = "";
|
|
135
|
+
const response = yield axios({
|
|
136
|
+
baseURL: this.endpoint,
|
|
137
|
+
url: "/translate",
|
|
138
|
+
method: "post",
|
|
139
|
+
headers: {
|
|
140
|
+
"Ocp-Apim-Subscription-Key": this.subscriptionKey,
|
|
141
|
+
"Ocp-Apim-Subscription-Region": this.subscriptionRegion,
|
|
142
|
+
"Content-type": "application/json",
|
|
143
|
+
"X-ClientTraceId": uuidv4().toString(),
|
|
144
|
+
},
|
|
145
|
+
params: {
|
|
146
|
+
"api-version": "3.0",
|
|
147
|
+
from: sourceLocale,
|
|
148
|
+
to: [targetLocale],
|
|
149
|
+
},
|
|
150
|
+
data: [
|
|
151
|
+
{
|
|
152
|
+
text: text,
|
|
153
|
+
},
|
|
154
|
+
],
|
|
155
|
+
responseType: "json",
|
|
156
|
+
});
|
|
157
|
+
result = response.data[0].translations[0].text;
|
|
158
|
+
result = util_1.Util.replaceArgumentsWithNumbers(args, result);
|
|
159
|
+
return result;
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
exports.AzureTranslate = AzureTranslate;
|
|
164
|
+
// https://docs.microsoft.com/en-us/azure/cognitive-services/translator/quickstart-translator?tabs=nodejs#translate-text
|
|
165
|
+
// Add your location, also known as region. The default is global.
|
|
166
|
+
// This is required if using a Cognitive Services resource.
|
|
167
|
+
/*
|
|
168
|
+
|
|
169
|
+
*/
|
package/config.d.ts
CHANGED
|
@@ -1,33 +1,38 @@
|
|
|
1
|
-
export
|
|
2
|
-
translationKeyInfo: GoogleTranslationKey | AwsTranslationKey | AzureTranslationKey | DeepLProTranslationKey | DeepLFreeTranslationKey;
|
|
3
|
-
startDelimiter: string;
|
|
4
|
-
endDelimiter: string;
|
|
5
|
-
mode:
|
|
6
|
-
sourceLocale: string;
|
|
7
|
-
keepTranslations:
|
|
8
|
-
keepExtraTranslations:
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
1
|
+
export type Configuration = {
|
|
2
|
+
translationKeyInfo: GoogleTranslationKey | AwsTranslationKey | AzureTranslationKey | DeepLProTranslationKey | DeepLFreeTranslationKey | OpenAITranslationKey;
|
|
3
|
+
startDelimiter: string;
|
|
4
|
+
endDelimiter: string;
|
|
5
|
+
mode: "file" | "folder";
|
|
6
|
+
sourceLocale: string;
|
|
7
|
+
keepTranslations: "keep" | "retranslate";
|
|
8
|
+
keepExtraTranslations: "keep" | "remove";
|
|
9
|
+
ignorePrefix: string;
|
|
10
|
+
};
|
|
11
|
+
type GoogleTranslationKey = {
|
|
12
|
+
kind: "google";
|
|
13
|
+
apiKey: string;
|
|
14
|
+
};
|
|
15
|
+
type AwsTranslationKey = {
|
|
16
|
+
kind: "aws";
|
|
17
|
+
accessKeyId: string;
|
|
18
|
+
secretAccessKey: string;
|
|
19
|
+
region: string;
|
|
20
|
+
};
|
|
21
|
+
type AzureTranslationKey = {
|
|
22
|
+
kind: "azure";
|
|
23
|
+
secretKey: string;
|
|
24
|
+
region: string;
|
|
25
|
+
};
|
|
26
|
+
type DeepLProTranslationKey = {
|
|
27
|
+
kind: "deepLPro";
|
|
28
|
+
secretKey: string;
|
|
29
|
+
};
|
|
30
|
+
type DeepLFreeTranslationKey = {
|
|
31
|
+
kind: "deepLFree";
|
|
32
|
+
secretKey: string;
|
|
33
|
+
};
|
|
34
|
+
type OpenAITranslationKey = {
|
|
35
|
+
kind: "openai";
|
|
36
|
+
apiKey: string;
|
|
37
|
+
};
|
|
38
|
+
export {};
|
package/config.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
package/deepl.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { ITranslate } from
|
|
2
|
-
export declare class DeepLTranslate implements ITranslate {
|
|
3
|
-
private subscriptionKey;
|
|
4
|
-
private type;
|
|
5
|
-
private endpoint;
|
|
6
|
-
constructor(subscriptionKey: string, type:
|
|
7
|
-
isValidLocale(targetLocale: string): boolean;
|
|
8
|
-
translateText(text: string, sourceLocale: string, targetLocale: string): Promise<string>;
|
|
9
|
-
}
|
|
1
|
+
import { ITranslate } from "./translate.interface";
|
|
2
|
+
export declare class DeepLTranslate implements ITranslate {
|
|
3
|
+
private subscriptionKey;
|
|
4
|
+
private type;
|
|
5
|
+
private endpoint;
|
|
6
|
+
constructor(subscriptionKey: string, type: "free" | "pro");
|
|
7
|
+
isValidLocale(targetLocale: string): boolean;
|
|
8
|
+
translateText(text: string, sourceLocale: string, targetLocale: string): Promise<string>;
|
|
9
|
+
}
|
package/deepl.js
CHANGED
|
@@ -1,82 +1,82 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.DeepLTranslate = void 0;
|
|
13
|
-
const FormData = require("form-data");
|
|
14
|
-
const axios = require(
|
|
15
|
-
const util_1 = require("./util");
|
|
16
|
-
const supportedLanguages = [
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
];
|
|
46
|
-
class DeepLTranslate {
|
|
47
|
-
constructor(subscriptionKey, type) {
|
|
48
|
-
this.subscriptionKey = subscriptionKey;
|
|
49
|
-
this.type = type;
|
|
50
|
-
this.endpoint =
|
|
51
|
-
if (this.type ===
|
|
52
|
-
this.endpoint =
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
isValidLocale(targetLocale) {
|
|
56
|
-
return supportedLanguages.includes(targetLocale.toUpperCase());
|
|
57
|
-
}
|
|
58
|
-
translateText(text, sourceLocale, targetLocale) {
|
|
59
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
60
|
-
let args;
|
|
61
|
-
({ args, text } = util_1.Util.replaceContextVariables(text));
|
|
62
|
-
let result =
|
|
63
|
-
const formData = new FormData();
|
|
64
|
-
formData.append(
|
|
65
|
-
formData.append(
|
|
66
|
-
formData.append(
|
|
67
|
-
formData.append(
|
|
68
|
-
const response = yield axios({
|
|
69
|
-
baseURL: this.endpoint,
|
|
70
|
-
url:
|
|
71
|
-
method:
|
|
72
|
-
data: formData,
|
|
73
|
-
responseType:
|
|
74
|
-
});
|
|
75
|
-
result = response.translations[1].text;
|
|
76
|
-
result = util_1.Util.replaceArgumentsWithNumbers(args, result);
|
|
77
|
-
return result;
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
exports.DeepLTranslate = DeepLTranslate;
|
|
82
|
-
// https://www.deepl.com/docs-api/translating-text/example/
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.DeepLTranslate = void 0;
|
|
13
|
+
const FormData = require("form-data");
|
|
14
|
+
const axios = require("axios").default;
|
|
15
|
+
const util_1 = require("./util");
|
|
16
|
+
const supportedLanguages = [
|
|
17
|
+
"BG",
|
|
18
|
+
"CS",
|
|
19
|
+
"DA",
|
|
20
|
+
"DE",
|
|
21
|
+
"EL",
|
|
22
|
+
"EN-GB",
|
|
23
|
+
"EN-US",
|
|
24
|
+
"EN",
|
|
25
|
+
"ES",
|
|
26
|
+
"ET",
|
|
27
|
+
"FI",
|
|
28
|
+
"FR",
|
|
29
|
+
"HU",
|
|
30
|
+
"IT",
|
|
31
|
+
"JA",
|
|
32
|
+
"LT",
|
|
33
|
+
"LV",
|
|
34
|
+
"NL",
|
|
35
|
+
"PL",
|
|
36
|
+
"PT-PT",
|
|
37
|
+
"PT-BR",
|
|
38
|
+
"PT",
|
|
39
|
+
"RO",
|
|
40
|
+
"RU",
|
|
41
|
+
"SK",
|
|
42
|
+
"SL",
|
|
43
|
+
"SV",
|
|
44
|
+
"ZH",
|
|
45
|
+
];
|
|
46
|
+
class DeepLTranslate {
|
|
47
|
+
constructor(subscriptionKey, type) {
|
|
48
|
+
this.subscriptionKey = subscriptionKey;
|
|
49
|
+
this.type = type;
|
|
50
|
+
this.endpoint = "https://api.deepl.com";
|
|
51
|
+
if (this.type === "free") {
|
|
52
|
+
this.endpoint = "https://api.free.deepl.com";
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
isValidLocale(targetLocale) {
|
|
56
|
+
return supportedLanguages.includes(targetLocale.toUpperCase());
|
|
57
|
+
}
|
|
58
|
+
translateText(text, sourceLocale, targetLocale) {
|
|
59
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
60
|
+
let args;
|
|
61
|
+
({ args, text } = util_1.Util.replaceContextVariables(text));
|
|
62
|
+
let result = "";
|
|
63
|
+
const formData = new FormData();
|
|
64
|
+
formData.append("auth_key", this.subscriptionKey);
|
|
65
|
+
formData.append("text", text);
|
|
66
|
+
formData.append("source_lang", sourceLocale.toUpperCase());
|
|
67
|
+
formData.append("target_lang", targetLocale.toUpperCase());
|
|
68
|
+
const response = yield axios({
|
|
69
|
+
baseURL: this.endpoint,
|
|
70
|
+
url: "v2/translate",
|
|
71
|
+
method: "post",
|
|
72
|
+
data: formData,
|
|
73
|
+
responseType: "json",
|
|
74
|
+
});
|
|
75
|
+
result = response.translations[1].text;
|
|
76
|
+
result = util_1.Util.replaceArgumentsWithNumbers(args, result);
|
|
77
|
+
return result;
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
exports.DeepLTranslate = DeepLTranslate;
|
|
82
|
+
// https://www.deepl.com/docs-api/translating-text/example/
|
package/files.d.ts
CHANGED
|
@@ -1,19 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
export declare const
|
|
9
|
-
export declare const
|
|
10
|
-
export declare
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
private
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
1
|
+
import { TranslationFile } from "./translate.interface";
|
|
2
|
+
export interface IFiles {
|
|
3
|
+
sourceLocale: string;
|
|
4
|
+
targetLocales: Array<string>;
|
|
5
|
+
loadJsonFromLocale(locale: string): Promise<TranslationFile>;
|
|
6
|
+
saveJsonToLocale(locale: string, file: TranslationFile): void;
|
|
7
|
+
}
|
|
8
|
+
export declare const readFileAsync: (filename: string) => Promise<string>;
|
|
9
|
+
export declare const loadJsonFromLocale: (fileName: string) => Promise<TranslationFile>;
|
|
10
|
+
export declare const saveJsonToLocale: (filename: string, file: TranslationFile) => void;
|
|
11
|
+
export declare class Files implements IFiles {
|
|
12
|
+
folderPath: string;
|
|
13
|
+
sourceLocale: string;
|
|
14
|
+
targetLocales: Array<string>;
|
|
15
|
+
constructor(filePath: string);
|
|
16
|
+
private getLocaleFromFilename;
|
|
17
|
+
private getTargetLocales;
|
|
18
|
+
loadJsonFromLocale(locale: string): Promise<TranslationFile>;
|
|
19
|
+
saveJsonToLocale(locale: string, file: TranslationFile): void;
|
|
20
|
+
}
|