@translated/lara 1.7.0 → 1.7.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/lib/documents.d.ts +57 -0
- package/lib/documents.js +76 -0
- package/lib/glossaries.d.ts +37 -0
- package/lib/glossaries.js +65 -0
- package/lib/index.d.ts +5 -3
- package/lib/index.js +11 -8
- package/lib/memories.d.ts +38 -0
- package/lib/memories.js +101 -0
- package/lib/net/browser-client.d.ts +1 -0
- package/lib/net/browser-client.js +77 -0
- package/lib/net/client.d.ts +3 -0
- package/lib/net/client.js +45 -1
- package/lib/net/index.d.ts +1 -1
- package/lib/net/index.js +2 -2
- package/lib/net/node-client.d.ts +2 -1
- package/lib/net/node-client.js +144 -4
- package/lib/net/s3/browser-client.d.ts +1 -1
- package/lib/net/s3/client.d.ts +1 -1
- package/lib/net/s3/node-client.d.ts +1 -1
- package/lib/translator.d.ts +68 -0
- package/lib/translator.js +67 -0
- package/lib/utils/sdk-version.d.ts +1 -0
- package/lib/{sdk-version.js → utils/sdk-version.js} +1 -1
- package/package.json +2 -2
- package/lib/sdk-version.d.ts +0 -1
- package/lib/translator/models.d.ts +0 -109
- package/lib/translator/models.js +0 -14
- package/lib/translator/translator.d.ts +0 -81
- package/lib/translator/translator.js +0 -272
- /package/lib/utils/{toSnakeCase.d.ts → to-snake-case.d.ts} +0 -0
- /package/lib/utils/{toSnakeCase.js → to-snake-case.js} +0 -0
|
@@ -1,272 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.Translator = exports.Glossaries = exports.Documents = exports.Memories = void 0;
|
|
7
|
-
const errors_1 = require("../errors");
|
|
8
|
-
const net_1 = __importDefault(require("../net"));
|
|
9
|
-
const s3_1 = __importDefault(require("../net/s3"));
|
|
10
|
-
const toSnakeCase_1 = __importDefault(require("../utils/toSnakeCase"));
|
|
11
|
-
const models_1 = require("./models");
|
|
12
|
-
class Memories {
|
|
13
|
-
constructor(client) {
|
|
14
|
-
this.client = client;
|
|
15
|
-
this.pollingInterval = 2000;
|
|
16
|
-
}
|
|
17
|
-
async list() {
|
|
18
|
-
return await this.client.get("/memories");
|
|
19
|
-
}
|
|
20
|
-
async create(name, externalId) {
|
|
21
|
-
return await this.client.post("/memories", {
|
|
22
|
-
name,
|
|
23
|
-
external_id: externalId
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
async get(id) {
|
|
27
|
-
try {
|
|
28
|
-
return await this.client.get(`/memories/${id}`);
|
|
29
|
-
}
|
|
30
|
-
catch (e) {
|
|
31
|
-
if (e instanceof errors_1.LaraApiError && e.statusCode === 404) {
|
|
32
|
-
return null;
|
|
33
|
-
}
|
|
34
|
-
throw e;
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
async delete(id) {
|
|
38
|
-
return await this.client.delete(`/memories/${id}`);
|
|
39
|
-
}
|
|
40
|
-
async update(id, name) {
|
|
41
|
-
return await this.client.put(`/memories/${id}`, { name });
|
|
42
|
-
}
|
|
43
|
-
async connect(ids) {
|
|
44
|
-
const memories = await this.client.post("/memories/connect", {
|
|
45
|
-
ids: Array.isArray(ids) ? ids : [ids]
|
|
46
|
-
});
|
|
47
|
-
return (Array.isArray(ids) ? memories : memories[0]);
|
|
48
|
-
}
|
|
49
|
-
async importTmx(id, tmx, gzip = false) {
|
|
50
|
-
return await this.client.post(`/memories/${id}/import`, {
|
|
51
|
-
compression: gzip ? "gzip" : undefined
|
|
52
|
-
}, {
|
|
53
|
-
tmx
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
async addTranslation(id, source, target, sentence, translation, tuid, sentenceBefore, sentenceAfter, headers) {
|
|
57
|
-
const body = {
|
|
58
|
-
source,
|
|
59
|
-
target,
|
|
60
|
-
sentence,
|
|
61
|
-
translation,
|
|
62
|
-
tuid,
|
|
63
|
-
sentence_before: sentenceBefore,
|
|
64
|
-
sentence_after: sentenceAfter
|
|
65
|
-
};
|
|
66
|
-
if (Array.isArray(id)) {
|
|
67
|
-
body.ids = id;
|
|
68
|
-
return await this.client.put("/memories/content", body, undefined, headers);
|
|
69
|
-
}
|
|
70
|
-
else {
|
|
71
|
-
return await this.client.put(`/memories/${id}/content`, body, undefined, headers);
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
async deleteTranslation(id, source, target, sentence, translation, tuid, sentenceBefore, sentenceAfter) {
|
|
75
|
-
const body = {
|
|
76
|
-
source,
|
|
77
|
-
target,
|
|
78
|
-
sentence,
|
|
79
|
-
translation,
|
|
80
|
-
tuid,
|
|
81
|
-
sentence_before: sentenceBefore,
|
|
82
|
-
sentence_after: sentenceAfter
|
|
83
|
-
};
|
|
84
|
-
if (Array.isArray(id)) {
|
|
85
|
-
body.ids = id;
|
|
86
|
-
return await this.client.delete("/memories/content", body);
|
|
87
|
-
}
|
|
88
|
-
else {
|
|
89
|
-
return await this.client.delete(`/memories/${id}/content`, body);
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
async getImportStatus(id) {
|
|
93
|
-
return await this.client.get(`/memories/imports/${id}`);
|
|
94
|
-
}
|
|
95
|
-
async waitForImport(mImport, updateCallback, maxWaitTime) {
|
|
96
|
-
const start = Date.now();
|
|
97
|
-
while (mImport.progress < 1.0) {
|
|
98
|
-
if (maxWaitTime && Date.now() - start > maxWaitTime)
|
|
99
|
-
throw new errors_1.TimeoutError();
|
|
100
|
-
await new Promise((resolve) => setTimeout(resolve, this.pollingInterval));
|
|
101
|
-
mImport = await this.getImportStatus(mImport.id);
|
|
102
|
-
if (updateCallback)
|
|
103
|
-
updateCallback(mImport);
|
|
104
|
-
}
|
|
105
|
-
return mImport;
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
exports.Memories = Memories;
|
|
109
|
-
class Documents {
|
|
110
|
-
constructor(client) {
|
|
111
|
-
this.client = client;
|
|
112
|
-
this.s3Client = (0, s3_1.default)();
|
|
113
|
-
}
|
|
114
|
-
async upload(file, filename, source, target, options) {
|
|
115
|
-
const { url, fields } = await this.client.get(`/documents/upload-url`, { filename });
|
|
116
|
-
await this.s3Client.upload(url, fields, file);
|
|
117
|
-
const headers = (options === null || options === void 0 ? void 0 : options.noTrace) ? { "X-No-Trace": "true" } : {};
|
|
118
|
-
return this.client.post("/documents", {
|
|
119
|
-
source,
|
|
120
|
-
target,
|
|
121
|
-
s3key: fields.key,
|
|
122
|
-
adapt_to: options === null || options === void 0 ? void 0 : options.adaptTo,
|
|
123
|
-
glossaries: options === null || options === void 0 ? void 0 : options.glossaries,
|
|
124
|
-
style: options === null || options === void 0 ? void 0 : options.style,
|
|
125
|
-
password: options === null || options === void 0 ? void 0 : options.password,
|
|
126
|
-
extraction_params: (options === null || options === void 0 ? void 0 : options.extractionParams) ? (0, toSnakeCase_1.default)(options.extractionParams) : undefined
|
|
127
|
-
}, undefined, headers);
|
|
128
|
-
}
|
|
129
|
-
async status(id) {
|
|
130
|
-
return await this.client.get(`/documents/${id}`);
|
|
131
|
-
}
|
|
132
|
-
async download(id, options) {
|
|
133
|
-
const { url } = await this.client.get(`/documents/${id}/download-url`, {
|
|
134
|
-
output_format: options === null || options === void 0 ? void 0 : options.outputFormat
|
|
135
|
-
});
|
|
136
|
-
return await this.s3Client.download(url);
|
|
137
|
-
}
|
|
138
|
-
async translate(file, filename, source, target, options) {
|
|
139
|
-
const uploadOptions = {
|
|
140
|
-
adaptTo: options === null || options === void 0 ? void 0 : options.adaptTo,
|
|
141
|
-
glossaries: options === null || options === void 0 ? void 0 : options.glossaries,
|
|
142
|
-
noTrace: options === null || options === void 0 ? void 0 : options.noTrace,
|
|
143
|
-
style: options === null || options === void 0 ? void 0 : options.style,
|
|
144
|
-
password: options === null || options === void 0 ? void 0 : options.password,
|
|
145
|
-
extractionParams: options === null || options === void 0 ? void 0 : options.extractionParams
|
|
146
|
-
};
|
|
147
|
-
const { id } = await this.upload(file, filename, source, target, uploadOptions);
|
|
148
|
-
const downloadOptions = (options === null || options === void 0 ? void 0 : options.outputFormat) ? { outputFormat: options.outputFormat } : undefined;
|
|
149
|
-
const pollingInterval = 2000;
|
|
150
|
-
const maxWaitTime = 1000 * 60 * 15; // 15 minutes
|
|
151
|
-
const start = Date.now();
|
|
152
|
-
while (Date.now() - start < maxWaitTime) {
|
|
153
|
-
await new Promise((resolve) => setTimeout(resolve, pollingInterval));
|
|
154
|
-
const { status, errorReason } = await this.status(id);
|
|
155
|
-
if (status === models_1.DocumentStatus.TRANSLATED)
|
|
156
|
-
return await this.download(id, downloadOptions);
|
|
157
|
-
if (status === models_1.DocumentStatus.ERROR) {
|
|
158
|
-
throw new errors_1.LaraApiError(500, "DocumentError", errorReason);
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
throw new errors_1.TimeoutError();
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
exports.Documents = Documents;
|
|
165
|
-
class Glossaries {
|
|
166
|
-
constructor(client) {
|
|
167
|
-
this.client = client;
|
|
168
|
-
this.pollingInterval = 2000;
|
|
169
|
-
}
|
|
170
|
-
async list() {
|
|
171
|
-
return await this.client.get("/glossaries");
|
|
172
|
-
}
|
|
173
|
-
async create(name) {
|
|
174
|
-
return await this.client.post("/glossaries", { name });
|
|
175
|
-
}
|
|
176
|
-
async get(id) {
|
|
177
|
-
try {
|
|
178
|
-
return await this.client.get(`/glossaries/${id}`);
|
|
179
|
-
}
|
|
180
|
-
catch (e) {
|
|
181
|
-
if (e instanceof errors_1.LaraApiError && e.statusCode === 404) {
|
|
182
|
-
return null;
|
|
183
|
-
}
|
|
184
|
-
throw e;
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
async delete(id) {
|
|
188
|
-
return await this.client.delete(`/glossaries/${id}`);
|
|
189
|
-
}
|
|
190
|
-
async update(id, name) {
|
|
191
|
-
return await this.client.put(`/glossaries/${id}`, { name });
|
|
192
|
-
}
|
|
193
|
-
async importCsv(id, csv, gzip = false) {
|
|
194
|
-
return await this.client.post(`/glossaries/${id}/import`, {
|
|
195
|
-
compression: gzip ? "gzip" : undefined
|
|
196
|
-
}, {
|
|
197
|
-
csv
|
|
198
|
-
});
|
|
199
|
-
}
|
|
200
|
-
async getImportStatus(id) {
|
|
201
|
-
return await this.client.get(`/glossaries/imports/${id}`);
|
|
202
|
-
}
|
|
203
|
-
async waitForImport(gImport, updateCallback, maxWaitTime) {
|
|
204
|
-
const start = Date.now();
|
|
205
|
-
while (gImport.progress < 1.0) {
|
|
206
|
-
if (maxWaitTime && Date.now() - start > maxWaitTime)
|
|
207
|
-
throw new errors_1.TimeoutError();
|
|
208
|
-
await new Promise((resolve) => setTimeout(resolve, this.pollingInterval));
|
|
209
|
-
gImport = await this.getImportStatus(gImport.id);
|
|
210
|
-
if (updateCallback)
|
|
211
|
-
updateCallback(gImport);
|
|
212
|
-
}
|
|
213
|
-
return gImport;
|
|
214
|
-
}
|
|
215
|
-
async counts(id) {
|
|
216
|
-
return await this.client.get(`/glossaries/${id}/counts`);
|
|
217
|
-
}
|
|
218
|
-
async export(id, contentType, source) {
|
|
219
|
-
return await this.client.get(`/glossaries/${id}/export`, {
|
|
220
|
-
content_type: contentType,
|
|
221
|
-
source
|
|
222
|
-
});
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
exports.Glossaries = Glossaries;
|
|
226
|
-
class Translator {
|
|
227
|
-
constructor(credentials, options) {
|
|
228
|
-
this.client = (0, net_1.default)(credentials.accessKeyId, credentials.accessKeySecret, options === null || options === void 0 ? void 0 : options.serverUrl);
|
|
229
|
-
this.memories = new Memories(this.client);
|
|
230
|
-
this.documents = new Documents(this.client);
|
|
231
|
-
this.glossaries = new Glossaries(this.client);
|
|
232
|
-
}
|
|
233
|
-
async getLanguages() {
|
|
234
|
-
return await this.client.get("/languages");
|
|
235
|
-
}
|
|
236
|
-
async translate(text, source, target, options) {
|
|
237
|
-
const headers = {};
|
|
238
|
-
if (options === null || options === void 0 ? void 0 : options.headers) {
|
|
239
|
-
for (const [name, value] of Object.entries(options.headers)) {
|
|
240
|
-
headers[name] = value;
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
if (options === null || options === void 0 ? void 0 : options.noTrace) {
|
|
244
|
-
headers["X-No-Trace"] = "true";
|
|
245
|
-
}
|
|
246
|
-
return await this.client.post("/translate", {
|
|
247
|
-
q: text,
|
|
248
|
-
source,
|
|
249
|
-
target,
|
|
250
|
-
source_hint: options === null || options === void 0 ? void 0 : options.sourceHint,
|
|
251
|
-
content_type: options === null || options === void 0 ? void 0 : options.contentType,
|
|
252
|
-
multiline: (options === null || options === void 0 ? void 0 : options.multiline) !== false,
|
|
253
|
-
adapt_to: options === null || options === void 0 ? void 0 : options.adaptTo,
|
|
254
|
-
glossaries: options === null || options === void 0 ? void 0 : options.glossaries,
|
|
255
|
-
instructions: options === null || options === void 0 ? void 0 : options.instructions,
|
|
256
|
-
timeout: options === null || options === void 0 ? void 0 : options.timeoutInMillis,
|
|
257
|
-
priority: options === null || options === void 0 ? void 0 : options.priority,
|
|
258
|
-
use_cache: options === null || options === void 0 ? void 0 : options.useCache,
|
|
259
|
-
cache_ttl: options === null || options === void 0 ? void 0 : options.cacheTTLSeconds,
|
|
260
|
-
verbose: options === null || options === void 0 ? void 0 : options.verbose,
|
|
261
|
-
style: options === null || options === void 0 ? void 0 : options.style
|
|
262
|
-
}, undefined, headers);
|
|
263
|
-
}
|
|
264
|
-
async detect(text, hint, passlist) {
|
|
265
|
-
return await this.client.post("/detect", {
|
|
266
|
-
q: text,
|
|
267
|
-
hint,
|
|
268
|
-
passlist
|
|
269
|
-
});
|
|
270
|
-
}
|
|
271
|
-
}
|
|
272
|
-
exports.Translator = Translator;
|
|
File without changes
|
|
File without changes
|