@translated/lara 1.5.5 → 1.6.0
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/sdk-version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const version = "1.
|
|
1
|
+
export declare const version = "1.6.0";
|
package/lib/sdk-version.js
CHANGED
|
@@ -28,6 +28,7 @@ export declare enum DocumentStatus {
|
|
|
28
28
|
}
|
|
29
29
|
export type DocumentUploadOptions = {
|
|
30
30
|
adaptTo?: string[];
|
|
31
|
+
glossaries?: string[];
|
|
31
32
|
noTrace?: boolean;
|
|
32
33
|
};
|
|
33
34
|
export type DocumentDownloadOptions = {
|
|
@@ -58,3 +59,22 @@ export interface TextResult<T extends string | string[] | TextBlock[]> {
|
|
|
58
59
|
readonly translation: T;
|
|
59
60
|
readonly adaptedTo?: string[];
|
|
60
61
|
}
|
|
62
|
+
export interface Glossary {
|
|
63
|
+
readonly id: string;
|
|
64
|
+
readonly name: string;
|
|
65
|
+
readonly ownerId: string;
|
|
66
|
+
readonly createdAt: Date;
|
|
67
|
+
readonly updatedAt: Date;
|
|
68
|
+
}
|
|
69
|
+
export interface GlossaryImport {
|
|
70
|
+
readonly id: string;
|
|
71
|
+
readonly begin: number;
|
|
72
|
+
readonly end: number;
|
|
73
|
+
readonly channel: number;
|
|
74
|
+
readonly size: number;
|
|
75
|
+
readonly progress: number;
|
|
76
|
+
}
|
|
77
|
+
export interface GlossaryCounts {
|
|
78
|
+
unidirectional?: Record<string, number>;
|
|
79
|
+
multidirectional?: number;
|
|
80
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Credentials } from "../credentials";
|
|
2
2
|
import { LaraClient } from "../net";
|
|
3
|
-
import { Document, DocumentDownloadOptions, DocumentUploadOptions, Memory, MemoryImport, TextBlock, TextResult } from "./models";
|
|
3
|
+
import { Document, DocumentDownloadOptions, DocumentUploadOptions, Glossary, GlossaryCounts, GlossaryImport, Memory, MemoryImport, TextBlock, TextResult } from "./models";
|
|
4
4
|
import { MultiPartFile } from "../net/client";
|
|
5
5
|
export type TranslatorOptions = {
|
|
6
6
|
serverUrl?: string;
|
|
@@ -26,6 +26,7 @@ export type TranslateOptions = {
|
|
|
26
26
|
sourceHint?: string;
|
|
27
27
|
adaptTo?: string[];
|
|
28
28
|
instructions?: string[];
|
|
29
|
+
glossaries?: string[];
|
|
29
30
|
contentType?: string;
|
|
30
31
|
multiline?: boolean;
|
|
31
32
|
timeoutInMillis?: number;
|
|
@@ -33,6 +34,7 @@ export type TranslateOptions = {
|
|
|
33
34
|
useCache?: boolean | "overwrite";
|
|
34
35
|
cacheTTLSeconds?: number;
|
|
35
36
|
noTrace?: boolean;
|
|
37
|
+
verbose?: boolean;
|
|
36
38
|
};
|
|
37
39
|
export type DocumentTranslateOptions = DocumentUploadOptions & DocumentDownloadOptions;
|
|
38
40
|
export type S3UploadFields = {
|
|
@@ -49,10 +51,27 @@ export declare class Documents {
|
|
|
49
51
|
download(id: string, options?: DocumentDownloadOptions): Promise<Blob | Buffer>;
|
|
50
52
|
translate(file: MultiPartFile, filename: string, source: string | null, target: string, options?: DocumentTranslateOptions): Promise<Blob | Buffer>;
|
|
51
53
|
}
|
|
54
|
+
export type GlossaryImportCallback = (glossaryImport: GlossaryImport) => void;
|
|
55
|
+
export declare class Glossaries {
|
|
56
|
+
private readonly client;
|
|
57
|
+
private readonly pollingInterval;
|
|
58
|
+
constructor(client: LaraClient);
|
|
59
|
+
list(): Promise<Glossary[]>;
|
|
60
|
+
create(name: string): Promise<Glossary>;
|
|
61
|
+
get(id: string): Promise<Glossary | null>;
|
|
62
|
+
delete(id: string): Promise<Glossary>;
|
|
63
|
+
update(id: string, name: string): Promise<Glossary>;
|
|
64
|
+
importCsv(id: string, csv: MultiPartFile, gzip?: boolean): Promise<GlossaryImport>;
|
|
65
|
+
getImportStatus(id: string): Promise<GlossaryImport>;
|
|
66
|
+
waitForImport(gImport: GlossaryImport, updateCallback?: GlossaryImportCallback, maxWaitTime?: number): Promise<GlossaryImport>;
|
|
67
|
+
counts(id: string): Promise<GlossaryCounts>;
|
|
68
|
+
export(id: string, contentType: 'csv/table-uni', source?: string): Promise<string>;
|
|
69
|
+
}
|
|
52
70
|
export declare class Translator {
|
|
53
71
|
protected readonly client: LaraClient;
|
|
54
72
|
readonly memories: Memories;
|
|
55
73
|
readonly documents: Documents;
|
|
74
|
+
readonly glossaries: Glossaries;
|
|
56
75
|
constructor(credentials: Credentials, options?: TranslatorOptions);
|
|
57
76
|
getLanguages(): Promise<string[]>;
|
|
58
77
|
translate<T extends string | string[] | TextBlock[]>(text: T, source: string | null, target: string, options?: TranslateOptions): Promise<TextResult<T>>;
|
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.Translator = exports.Documents = exports.Memories = void 0;
|
|
6
|
+
exports.Translator = exports.Glossaries = exports.Documents = exports.Memories = void 0;
|
|
7
7
|
const net_1 = __importDefault(require("../net"));
|
|
8
8
|
const s3_1 = __importDefault(require("../net/s3"));
|
|
9
9
|
const models_1 = require("./models");
|
|
@@ -118,6 +118,7 @@ class Documents {
|
|
|
118
118
|
target,
|
|
119
119
|
s3key: fields.key,
|
|
120
120
|
adapt_to: options === null || options === void 0 ? void 0 : options.adaptTo,
|
|
121
|
+
glossaries: options === null || options === void 0 ? void 0 : options.glossaries,
|
|
121
122
|
}, undefined, headers);
|
|
122
123
|
}
|
|
123
124
|
async status(id) {
|
|
@@ -132,6 +133,7 @@ class Documents {
|
|
|
132
133
|
async translate(file, filename, source, target, options) {
|
|
133
134
|
const uploadOptions = {
|
|
134
135
|
adaptTo: options === null || options === void 0 ? void 0 : options.adaptTo,
|
|
136
|
+
glossaries: options === null || options === void 0 ? void 0 : options.glossaries,
|
|
135
137
|
noTrace: options === null || options === void 0 ? void 0 : options.noTrace
|
|
136
138
|
};
|
|
137
139
|
const { id } = await this.upload(file, filename, source, target, uploadOptions);
|
|
@@ -152,11 +154,73 @@ class Documents {
|
|
|
152
154
|
}
|
|
153
155
|
}
|
|
154
156
|
exports.Documents = Documents;
|
|
157
|
+
class Glossaries {
|
|
158
|
+
constructor(client) {
|
|
159
|
+
this.client = client;
|
|
160
|
+
this.pollingInterval = 2000;
|
|
161
|
+
}
|
|
162
|
+
async list() {
|
|
163
|
+
return await this.client.get('/glossaries');
|
|
164
|
+
}
|
|
165
|
+
async create(name) {
|
|
166
|
+
return await this.client.post('/glossaries', { name });
|
|
167
|
+
}
|
|
168
|
+
async get(id) {
|
|
169
|
+
try {
|
|
170
|
+
return await this.client.get(`/glossaries/${id}`);
|
|
171
|
+
}
|
|
172
|
+
catch (e) {
|
|
173
|
+
if (e instanceof errors_1.LaraApiError && e.statusCode === 404) {
|
|
174
|
+
return null;
|
|
175
|
+
}
|
|
176
|
+
throw e;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
async delete(id) {
|
|
180
|
+
return await this.client.delete(`/glossaries/${id}`);
|
|
181
|
+
}
|
|
182
|
+
async update(id, name) {
|
|
183
|
+
return await this.client.put(`/glossaries/${id}`, { name });
|
|
184
|
+
}
|
|
185
|
+
async importCsv(id, csv, gzip = false) {
|
|
186
|
+
return await this.client.post(`/glossaries/${id}/import`, {
|
|
187
|
+
compression: gzip ? 'gzip' : undefined
|
|
188
|
+
}, {
|
|
189
|
+
csv
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
async getImportStatus(id) {
|
|
193
|
+
return await this.client.get(`/glossaries/imports/${id}`);
|
|
194
|
+
}
|
|
195
|
+
async waitForImport(gImport, updateCallback, maxWaitTime) {
|
|
196
|
+
const start = Date.now();
|
|
197
|
+
while (gImport.progress < 1.) {
|
|
198
|
+
if (maxWaitTime && Date.now() - start > maxWaitTime)
|
|
199
|
+
throw new errors_1.TimeoutError();
|
|
200
|
+
await new Promise(resolve => setTimeout(resolve, this.pollingInterval));
|
|
201
|
+
gImport = await this.getImportStatus(gImport.id);
|
|
202
|
+
if (updateCallback)
|
|
203
|
+
updateCallback(gImport);
|
|
204
|
+
}
|
|
205
|
+
return gImport;
|
|
206
|
+
}
|
|
207
|
+
async counts(id) {
|
|
208
|
+
return await this.client.get(`/glossaries/${id}/counts`);
|
|
209
|
+
}
|
|
210
|
+
async export(id, contentType, source) {
|
|
211
|
+
return await this.client.get(`/glossaries/${id}/export`, {
|
|
212
|
+
content_type: contentType,
|
|
213
|
+
source
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
exports.Glossaries = Glossaries;
|
|
155
218
|
class Translator {
|
|
156
219
|
constructor(credentials, options) {
|
|
157
220
|
this.client = (0, net_1.default)(credentials.accessKeyId, credentials.accessKeySecret, options === null || options === void 0 ? void 0 : options.serverUrl);
|
|
158
221
|
this.memories = new Memories(this.client);
|
|
159
222
|
this.documents = new Documents(this.client);
|
|
223
|
+
this.glossaries = new Glossaries(this.client);
|
|
160
224
|
}
|
|
161
225
|
async getLanguages() {
|
|
162
226
|
return await this.client.get("/languages");
|
|
@@ -166,9 +230,10 @@ class Translator {
|
|
|
166
230
|
return await this.client.post("/translate", {
|
|
167
231
|
q: text, source, target, source_hint: options === null || options === void 0 ? void 0 : options.sourceHint,
|
|
168
232
|
content_type: options === null || options === void 0 ? void 0 : options.contentType, multiline: (options === null || options === void 0 ? void 0 : options.multiline) !== false,
|
|
169
|
-
adapt_to: options === null || options === void 0 ? void 0 : options.adaptTo, instructions: options === null || options === void 0 ? void 0 : options.instructions,
|
|
233
|
+
adapt_to: options === null || options === void 0 ? void 0 : options.adaptTo, glossaries: options === null || options === void 0 ? void 0 : options.glossaries, instructions: options === null || options === void 0 ? void 0 : options.instructions,
|
|
170
234
|
timeout: options === null || options === void 0 ? void 0 : options.timeoutInMillis, priority: options === null || options === void 0 ? void 0 : options.priority,
|
|
171
|
-
use_cache: options === null || options === void 0 ? void 0 : options.useCache, cache_ttl: options === null || options === void 0 ? void 0 : options.cacheTTLSeconds
|
|
235
|
+
use_cache: options === null || options === void 0 ? void 0 : options.useCache, cache_ttl: options === null || options === void 0 ? void 0 : options.cacheTTLSeconds,
|
|
236
|
+
verbose: options === null || options === void 0 ? void 0 : options.verbose,
|
|
172
237
|
}, undefined, headers);
|
|
173
238
|
}
|
|
174
239
|
}
|