@translated/lara 1.7.0 → 1.7.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/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/client.js +1 -1
- package/lib/net/index.d.ts +1 -1
- package/lib/net/index.js +2 -2
- package/lib/net/node-client.d.ts +1 -1
- package/lib/net/node-client.js +13 -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 +67 -0
- package/lib/translator.js +57 -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
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import type { LaraClient } from "./net";
|
|
2
|
+
import type { MultiPartFile } from "./net/client";
|
|
3
|
+
import type { TranslationStyle } from "./translator";
|
|
4
|
+
export type S3UploadFields = {
|
|
5
|
+
acl: string;
|
|
6
|
+
bucket: string;
|
|
7
|
+
key: string;
|
|
8
|
+
};
|
|
9
|
+
export declare enum DocumentStatus {
|
|
10
|
+
INITIALIZED = "initialized",// just been created
|
|
11
|
+
ANALYZING = "analyzing",// being analyzed for language detection and chars count
|
|
12
|
+
PAUSED = "paused",// paused after analysis, needs user confirm
|
|
13
|
+
READY = "ready",// ready to be translated
|
|
14
|
+
TRANSLATING = "translating",
|
|
15
|
+
TRANSLATED = "translated",
|
|
16
|
+
ERROR = "error"
|
|
17
|
+
}
|
|
18
|
+
export interface DocxExtractionParams {
|
|
19
|
+
extractComments?: boolean;
|
|
20
|
+
acceptRevisions?: boolean;
|
|
21
|
+
}
|
|
22
|
+
export type DocumentOptions = {
|
|
23
|
+
adaptTo?: string[];
|
|
24
|
+
glossaries?: string[];
|
|
25
|
+
noTrace?: boolean;
|
|
26
|
+
style?: TranslationStyle;
|
|
27
|
+
};
|
|
28
|
+
export type DocumentDownloadOptions = {
|
|
29
|
+
outputFormat?: string;
|
|
30
|
+
};
|
|
31
|
+
export type DocumentUploadOptions = DocumentOptions & {
|
|
32
|
+
password?: string;
|
|
33
|
+
extractionParams?: DocxExtractionParams;
|
|
34
|
+
};
|
|
35
|
+
export interface Document {
|
|
36
|
+
readonly id: string;
|
|
37
|
+
readonly status: DocumentStatus;
|
|
38
|
+
readonly source?: string;
|
|
39
|
+
readonly target: string;
|
|
40
|
+
readonly filename: string;
|
|
41
|
+
readonly createdAt: Date;
|
|
42
|
+
readonly updatedAt: Date;
|
|
43
|
+
readonly options?: DocumentOptions;
|
|
44
|
+
readonly translatedChars?: number;
|
|
45
|
+
readonly totalChars?: number;
|
|
46
|
+
readonly errorReason?: string;
|
|
47
|
+
}
|
|
48
|
+
export type DocumentTranslateOptions = DocumentUploadOptions & DocumentDownloadOptions;
|
|
49
|
+
export declare class Documents {
|
|
50
|
+
private readonly client;
|
|
51
|
+
private readonly s3Client;
|
|
52
|
+
constructor(client: LaraClient);
|
|
53
|
+
upload(file: MultiPartFile, filename: string, source: string | null, target: string, options?: DocumentUploadOptions): Promise<Document>;
|
|
54
|
+
status(id: string): Promise<Document>;
|
|
55
|
+
download(id: string, options?: DocumentDownloadOptions): Promise<Blob | Buffer>;
|
|
56
|
+
translate(file: MultiPartFile, filename: string, source: string | null, target: string, options?: DocumentTranslateOptions): Promise<Blob | Buffer>;
|
|
57
|
+
}
|
package/lib/documents.js
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
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.Documents = exports.DocumentStatus = void 0;
|
|
7
|
+
const errors_1 = require("./errors");
|
|
8
|
+
const s3_1 = __importDefault(require("./net/s3"));
|
|
9
|
+
const to_snake_case_1 = __importDefault(require("./utils/to-snake-case"));
|
|
10
|
+
// biome-ignore format: keep comments aligned
|
|
11
|
+
var DocumentStatus;
|
|
12
|
+
(function (DocumentStatus) {
|
|
13
|
+
DocumentStatus["INITIALIZED"] = "initialized";
|
|
14
|
+
DocumentStatus["ANALYZING"] = "analyzing";
|
|
15
|
+
DocumentStatus["PAUSED"] = "paused";
|
|
16
|
+
DocumentStatus["READY"] = "ready";
|
|
17
|
+
DocumentStatus["TRANSLATING"] = "translating";
|
|
18
|
+
DocumentStatus["TRANSLATED"] = "translated";
|
|
19
|
+
DocumentStatus["ERROR"] = "error";
|
|
20
|
+
})(DocumentStatus || (exports.DocumentStatus = DocumentStatus = {}));
|
|
21
|
+
class Documents {
|
|
22
|
+
constructor(client) {
|
|
23
|
+
this.client = client;
|
|
24
|
+
this.s3Client = (0, s3_1.default)();
|
|
25
|
+
}
|
|
26
|
+
async upload(file, filename, source, target, options) {
|
|
27
|
+
const { url, fields } = await this.client.get(`/documents/upload-url`, { filename });
|
|
28
|
+
await this.s3Client.upload(url, fields, file);
|
|
29
|
+
const headers = (options === null || options === void 0 ? void 0 : options.noTrace) ? { "X-No-Trace": "true" } : {};
|
|
30
|
+
return this.client.post("/documents", {
|
|
31
|
+
source,
|
|
32
|
+
target,
|
|
33
|
+
s3key: fields.key,
|
|
34
|
+
adapt_to: options === null || options === void 0 ? void 0 : options.adaptTo,
|
|
35
|
+
glossaries: options === null || options === void 0 ? void 0 : options.glossaries,
|
|
36
|
+
style: options === null || options === void 0 ? void 0 : options.style,
|
|
37
|
+
password: options === null || options === void 0 ? void 0 : options.password,
|
|
38
|
+
extraction_params: (options === null || options === void 0 ? void 0 : options.extractionParams) ? (0, to_snake_case_1.default)(options.extractionParams) : undefined
|
|
39
|
+
}, undefined, headers);
|
|
40
|
+
}
|
|
41
|
+
async status(id) {
|
|
42
|
+
return await this.client.get(`/documents/${id}`);
|
|
43
|
+
}
|
|
44
|
+
async download(id, options) {
|
|
45
|
+
const { url } = await this.client.get(`/documents/${id}/download-url`, {
|
|
46
|
+
output_format: options === null || options === void 0 ? void 0 : options.outputFormat
|
|
47
|
+
});
|
|
48
|
+
return await this.s3Client.download(url);
|
|
49
|
+
}
|
|
50
|
+
async translate(file, filename, source, target, options) {
|
|
51
|
+
const uploadOptions = {
|
|
52
|
+
adaptTo: options === null || options === void 0 ? void 0 : options.adaptTo,
|
|
53
|
+
glossaries: options === null || options === void 0 ? void 0 : options.glossaries,
|
|
54
|
+
noTrace: options === null || options === void 0 ? void 0 : options.noTrace,
|
|
55
|
+
style: options === null || options === void 0 ? void 0 : options.style,
|
|
56
|
+
password: options === null || options === void 0 ? void 0 : options.password,
|
|
57
|
+
extractionParams: options === null || options === void 0 ? void 0 : options.extractionParams
|
|
58
|
+
};
|
|
59
|
+
const { id } = await this.upload(file, filename, source, target, uploadOptions);
|
|
60
|
+
const downloadOptions = (options === null || options === void 0 ? void 0 : options.outputFormat) ? { outputFormat: options.outputFormat } : undefined;
|
|
61
|
+
const pollingInterval = 2000;
|
|
62
|
+
const maxWaitTime = 1000 * 60 * 15; // 15 minutes
|
|
63
|
+
const start = Date.now();
|
|
64
|
+
while (Date.now() - start < maxWaitTime) {
|
|
65
|
+
await new Promise((resolve) => setTimeout(resolve, pollingInterval));
|
|
66
|
+
const { status, errorReason } = await this.status(id);
|
|
67
|
+
if (status === DocumentStatus.TRANSLATED)
|
|
68
|
+
return await this.download(id, downloadOptions);
|
|
69
|
+
if (status === DocumentStatus.ERROR) {
|
|
70
|
+
throw new errors_1.LaraApiError(500, "DocumentError", errorReason);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
throw new errors_1.TimeoutError();
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
exports.Documents = Documents;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { LaraClient } from "./net";
|
|
2
|
+
import type { MultiPartFile } from "./net/client";
|
|
3
|
+
export interface Glossary {
|
|
4
|
+
readonly id: string;
|
|
5
|
+
readonly name: string;
|
|
6
|
+
readonly ownerId: string;
|
|
7
|
+
readonly createdAt: Date;
|
|
8
|
+
readonly updatedAt: Date;
|
|
9
|
+
}
|
|
10
|
+
export interface GlossaryImport {
|
|
11
|
+
readonly id: string;
|
|
12
|
+
readonly begin: number;
|
|
13
|
+
readonly end: number;
|
|
14
|
+
readonly channel: number;
|
|
15
|
+
readonly size: number;
|
|
16
|
+
readonly progress: number;
|
|
17
|
+
}
|
|
18
|
+
export interface GlossaryCounts {
|
|
19
|
+
unidirectional?: Record<string, number>;
|
|
20
|
+
multidirectional?: number;
|
|
21
|
+
}
|
|
22
|
+
export type GlossaryImportCallback = (glossaryImport: GlossaryImport) => void;
|
|
23
|
+
export declare class Glossaries {
|
|
24
|
+
private readonly client;
|
|
25
|
+
private readonly pollingInterval;
|
|
26
|
+
constructor(client: LaraClient);
|
|
27
|
+
list(): Promise<Glossary[]>;
|
|
28
|
+
create(name: string): Promise<Glossary>;
|
|
29
|
+
get(id: string): Promise<Glossary | null>;
|
|
30
|
+
delete(id: string): Promise<Glossary>;
|
|
31
|
+
update(id: string, name: string): Promise<Glossary>;
|
|
32
|
+
importCsv(id: string, csv: MultiPartFile, gzip?: boolean): Promise<GlossaryImport>;
|
|
33
|
+
getImportStatus(id: string): Promise<GlossaryImport>;
|
|
34
|
+
waitForImport(gImport: GlossaryImport, updateCallback?: GlossaryImportCallback, maxWaitTime?: number): Promise<GlossaryImport>;
|
|
35
|
+
counts(id: string): Promise<GlossaryCounts>;
|
|
36
|
+
export(id: string, contentType: "csv/table-uni", source?: string): Promise<string>;
|
|
37
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Glossaries = void 0;
|
|
4
|
+
const errors_1 = require("./errors");
|
|
5
|
+
class Glossaries {
|
|
6
|
+
constructor(client) {
|
|
7
|
+
this.client = client;
|
|
8
|
+
this.pollingInterval = 2000;
|
|
9
|
+
}
|
|
10
|
+
async list() {
|
|
11
|
+
return await this.client.get("/glossaries");
|
|
12
|
+
}
|
|
13
|
+
async create(name) {
|
|
14
|
+
return await this.client.post("/glossaries", { name });
|
|
15
|
+
}
|
|
16
|
+
async get(id) {
|
|
17
|
+
try {
|
|
18
|
+
return await this.client.get(`/glossaries/${id}`);
|
|
19
|
+
}
|
|
20
|
+
catch (e) {
|
|
21
|
+
if (e instanceof errors_1.LaraApiError && e.statusCode === 404) {
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
throw e;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
async delete(id) {
|
|
28
|
+
return await this.client.delete(`/glossaries/${id}`);
|
|
29
|
+
}
|
|
30
|
+
async update(id, name) {
|
|
31
|
+
return await this.client.put(`/glossaries/${id}`, { name });
|
|
32
|
+
}
|
|
33
|
+
async importCsv(id, csv, gzip = false) {
|
|
34
|
+
return await this.client.post(`/glossaries/${id}/import`, {
|
|
35
|
+
compression: gzip ? "gzip" : undefined
|
|
36
|
+
}, {
|
|
37
|
+
csv
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
async getImportStatus(id) {
|
|
41
|
+
return await this.client.get(`/glossaries/imports/${id}`);
|
|
42
|
+
}
|
|
43
|
+
async waitForImport(gImport, updateCallback, maxWaitTime) {
|
|
44
|
+
const start = Date.now();
|
|
45
|
+
while (gImport.progress < 1.0) {
|
|
46
|
+
if (maxWaitTime && Date.now() - start > maxWaitTime)
|
|
47
|
+
throw new errors_1.TimeoutError();
|
|
48
|
+
await new Promise((resolve) => setTimeout(resolve, this.pollingInterval));
|
|
49
|
+
gImport = await this.getImportStatus(gImport.id);
|
|
50
|
+
if (updateCallback)
|
|
51
|
+
updateCallback(gImport);
|
|
52
|
+
}
|
|
53
|
+
return gImport;
|
|
54
|
+
}
|
|
55
|
+
async counts(id) {
|
|
56
|
+
return await this.client.get(`/glossaries/${id}/counts`);
|
|
57
|
+
}
|
|
58
|
+
async export(id, contentType, source) {
|
|
59
|
+
return await this.client.get(`/glossaries/${id}/export`, {
|
|
60
|
+
content_type: contentType,
|
|
61
|
+
source
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
exports.Glossaries = Glossaries;
|
package/lib/index.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
export { Credentials } from "./credentials";
|
|
2
|
+
export { Document, DocumentDownloadOptions, DocumentStatus, Documents, DocumentTranslateOptions, DocumentUploadOptions } from "./documents";
|
|
2
3
|
export { LaraApiError, LaraError, TimeoutError } from "./errors";
|
|
4
|
+
export { Glossaries, GlossaryImport, GlossaryImportCallback } from "./glossaries";
|
|
5
|
+
export { Memories, Memory, MemoryImport, MemoryImportCallback } from "./memories";
|
|
3
6
|
export { MultiPartFile } from "./net/client";
|
|
4
|
-
export {
|
|
5
|
-
export {
|
|
6
|
-
export { Documents, DocumentTranslateOptions, Memories, MemoryImportCallback, TranslateOptions, Translator, TranslatorOptions } from "./translator/translator";
|
|
7
|
+
export { DetectResult, NGGlossaryMatch, NGMemoryMatch, TextBlock, TextResult, TranslateOptions, Translator, TranslatorOptions } from "./translator";
|
|
8
|
+
export { version } from "./utils/sdk-version";
|
package/lib/index.js
CHANGED
|
@@ -1,17 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Translator = exports.Memories = exports.
|
|
3
|
+
exports.version = exports.Translator = exports.Memories = exports.Glossaries = exports.TimeoutError = exports.LaraError = exports.LaraApiError = exports.Documents = exports.DocumentStatus = exports.Credentials = void 0;
|
|
4
4
|
var credentials_1 = require("./credentials");
|
|
5
5
|
Object.defineProperty(exports, "Credentials", { enumerable: true, get: function () { return credentials_1.Credentials; } });
|
|
6
|
+
var documents_1 = require("./documents");
|
|
7
|
+
Object.defineProperty(exports, "DocumentStatus", { enumerable: true, get: function () { return documents_1.DocumentStatus; } });
|
|
8
|
+
Object.defineProperty(exports, "Documents", { enumerable: true, get: function () { return documents_1.Documents; } });
|
|
6
9
|
var errors_1 = require("./errors");
|
|
7
10
|
Object.defineProperty(exports, "LaraApiError", { enumerable: true, get: function () { return errors_1.LaraApiError; } });
|
|
8
11
|
Object.defineProperty(exports, "LaraError", { enumerable: true, get: function () { return errors_1.LaraError; } });
|
|
9
12
|
Object.defineProperty(exports, "TimeoutError", { enumerable: true, get: function () { return errors_1.TimeoutError; } });
|
|
10
|
-
var
|
|
11
|
-
Object.defineProperty(exports, "
|
|
12
|
-
var
|
|
13
|
-
Object.defineProperty(exports, "
|
|
14
|
-
var translator_1 = require("./translator
|
|
15
|
-
Object.defineProperty(exports, "Documents", { enumerable: true, get: function () { return translator_1.Documents; } });
|
|
16
|
-
Object.defineProperty(exports, "Memories", { enumerable: true, get: function () { return translator_1.Memories; } });
|
|
13
|
+
var glossaries_1 = require("./glossaries");
|
|
14
|
+
Object.defineProperty(exports, "Glossaries", { enumerable: true, get: function () { return glossaries_1.Glossaries; } });
|
|
15
|
+
var memories_1 = require("./memories");
|
|
16
|
+
Object.defineProperty(exports, "Memories", { enumerable: true, get: function () { return memories_1.Memories; } });
|
|
17
|
+
var translator_1 = require("./translator");
|
|
17
18
|
Object.defineProperty(exports, "Translator", { enumerable: true, get: function () { return translator_1.Translator; } });
|
|
19
|
+
var sdk_version_1 = require("./utils/sdk-version");
|
|
20
|
+
Object.defineProperty(exports, "version", { enumerable: true, get: function () { return sdk_version_1.version; } });
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { LaraClient } from "./net";
|
|
2
|
+
import type { MultiPartFile } from "./net/client";
|
|
3
|
+
export interface Memory {
|
|
4
|
+
readonly id: string;
|
|
5
|
+
readonly createdAt: Date;
|
|
6
|
+
readonly updatedAt: Date;
|
|
7
|
+
readonly sharedAt: Date;
|
|
8
|
+
readonly name: string;
|
|
9
|
+
readonly externalId?: string;
|
|
10
|
+
readonly secret?: string;
|
|
11
|
+
readonly ownerId: string;
|
|
12
|
+
readonly collaboratorsCount: number;
|
|
13
|
+
}
|
|
14
|
+
export interface MemoryImport {
|
|
15
|
+
readonly id: string;
|
|
16
|
+
readonly begin: number;
|
|
17
|
+
readonly end: number;
|
|
18
|
+
readonly channel: number;
|
|
19
|
+
readonly size: number;
|
|
20
|
+
readonly progress: number;
|
|
21
|
+
}
|
|
22
|
+
export type MemoryImportCallback = (memoryImport: MemoryImport) => void;
|
|
23
|
+
export declare class Memories {
|
|
24
|
+
private readonly client;
|
|
25
|
+
private readonly pollingInterval;
|
|
26
|
+
constructor(client: LaraClient);
|
|
27
|
+
list(): Promise<Memory[]>;
|
|
28
|
+
create(name: string, externalId?: string): Promise<Memory>;
|
|
29
|
+
get(id: string): Promise<Memory | null>;
|
|
30
|
+
delete(id: string): Promise<Memory>;
|
|
31
|
+
update(id: string, name: string): Promise<Memory>;
|
|
32
|
+
connect<T extends string | string[]>(ids: T): Promise<T extends string ? Memory : Memory[]>;
|
|
33
|
+
importTmx(id: string, tmx: MultiPartFile, gzip?: boolean): Promise<MemoryImport>;
|
|
34
|
+
addTranslation(id: string | string[], source: string, target: string, sentence: string, translation: string, tuid?: string, sentenceBefore?: string, sentenceAfter?: string, headers?: Record<string, string>): Promise<MemoryImport>;
|
|
35
|
+
deleteTranslation(id: string | string[], source: string, target: string, sentence?: string, translation?: string, tuid?: string, sentenceBefore?: string, sentenceAfter?: string): Promise<MemoryImport>;
|
|
36
|
+
getImportStatus(id: string): Promise<MemoryImport>;
|
|
37
|
+
waitForImport(mImport: MemoryImport, updateCallback?: MemoryImportCallback, maxWaitTime?: number): Promise<MemoryImport>;
|
|
38
|
+
}
|
package/lib/memories.js
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Memories = void 0;
|
|
4
|
+
const errors_1 = require("./errors");
|
|
5
|
+
class Memories {
|
|
6
|
+
constructor(client) {
|
|
7
|
+
this.client = client;
|
|
8
|
+
this.pollingInterval = 2000;
|
|
9
|
+
}
|
|
10
|
+
async list() {
|
|
11
|
+
return await this.client.get("/memories");
|
|
12
|
+
}
|
|
13
|
+
async create(name, externalId) {
|
|
14
|
+
return await this.client.post("/memories", {
|
|
15
|
+
name,
|
|
16
|
+
external_id: externalId
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
async get(id) {
|
|
20
|
+
try {
|
|
21
|
+
return await this.client.get(`/memories/${id}`);
|
|
22
|
+
}
|
|
23
|
+
catch (e) {
|
|
24
|
+
if (e instanceof errors_1.LaraApiError && e.statusCode === 404) {
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
throw e;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
async delete(id) {
|
|
31
|
+
return await this.client.delete(`/memories/${id}`);
|
|
32
|
+
}
|
|
33
|
+
async update(id, name) {
|
|
34
|
+
return await this.client.put(`/memories/${id}`, { name });
|
|
35
|
+
}
|
|
36
|
+
async connect(ids) {
|
|
37
|
+
const memories = await this.client.post("/memories/connect", {
|
|
38
|
+
ids: Array.isArray(ids) ? ids : [ids]
|
|
39
|
+
});
|
|
40
|
+
return (Array.isArray(ids) ? memories : memories[0]);
|
|
41
|
+
}
|
|
42
|
+
async importTmx(id, tmx, gzip = false) {
|
|
43
|
+
return await this.client.post(`/memories/${id}/import`, {
|
|
44
|
+
compression: gzip ? "gzip" : undefined
|
|
45
|
+
}, {
|
|
46
|
+
tmx
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
async addTranslation(id, source, target, sentence, translation, tuid, sentenceBefore, sentenceAfter, headers) {
|
|
50
|
+
const body = {
|
|
51
|
+
source,
|
|
52
|
+
target,
|
|
53
|
+
sentence,
|
|
54
|
+
translation,
|
|
55
|
+
tuid,
|
|
56
|
+
sentence_before: sentenceBefore,
|
|
57
|
+
sentence_after: sentenceAfter
|
|
58
|
+
};
|
|
59
|
+
if (Array.isArray(id)) {
|
|
60
|
+
body.ids = id;
|
|
61
|
+
return await this.client.put("/memories/content", body, undefined, headers);
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
return await this.client.put(`/memories/${id}/content`, body, undefined, headers);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
async deleteTranslation(id, source, target, sentence, translation, tuid, sentenceBefore, sentenceAfter) {
|
|
68
|
+
const body = {
|
|
69
|
+
source,
|
|
70
|
+
target,
|
|
71
|
+
sentence,
|
|
72
|
+
translation,
|
|
73
|
+
tuid,
|
|
74
|
+
sentence_before: sentenceBefore,
|
|
75
|
+
sentence_after: sentenceAfter
|
|
76
|
+
};
|
|
77
|
+
if (Array.isArray(id)) {
|
|
78
|
+
body.ids = id;
|
|
79
|
+
return await this.client.delete("/memories/content", body);
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
return await this.client.delete(`/memories/${id}/content`, body);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
async getImportStatus(id) {
|
|
86
|
+
return await this.client.get(`/memories/imports/${id}`);
|
|
87
|
+
}
|
|
88
|
+
async waitForImport(mImport, updateCallback, maxWaitTime) {
|
|
89
|
+
const start = Date.now();
|
|
90
|
+
while (mImport.progress < 1.0) {
|
|
91
|
+
if (maxWaitTime && Date.now() - start > maxWaitTime)
|
|
92
|
+
throw new errors_1.TimeoutError();
|
|
93
|
+
await new Promise((resolve) => setTimeout(resolve, this.pollingInterval));
|
|
94
|
+
mImport = await this.getImportStatus(mImport.id);
|
|
95
|
+
if (updateCallback)
|
|
96
|
+
updateCallback(mImport);
|
|
97
|
+
}
|
|
98
|
+
return mImport;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
exports.Memories = Memories;
|
package/lib/net/client.js
CHANGED
|
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.LaraClient = void 0;
|
|
7
7
|
const crypto_1 = __importDefault(require("../crypto"));
|
|
8
8
|
const errors_1 = require("../errors");
|
|
9
|
-
const sdk_version_1 = require("../sdk-version");
|
|
9
|
+
const sdk_version_1 = require("../utils/sdk-version");
|
|
10
10
|
function parseContent(content) {
|
|
11
11
|
if (content === undefined || content === null)
|
|
12
12
|
return content;
|
package/lib/net/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { LaraClient } from "./client";
|
|
2
2
|
export { LaraClient } from "./client";
|
|
3
|
-
export default function create(accessKeyId: string, accessKeySecret: string, baseUrl?: string): LaraClient;
|
|
3
|
+
export default function create(accessKeyId: string, accessKeySecret: string, baseUrl?: string, keepAlive?: boolean): LaraClient;
|
package/lib/net/index.js
CHANGED
|
@@ -7,7 +7,7 @@ const node_client_1 = require("./node-client");
|
|
|
7
7
|
var client_1 = require("./client");
|
|
8
8
|
Object.defineProperty(exports, "LaraClient", { enumerable: true, get: function () { return client_1.LaraClient; } });
|
|
9
9
|
const DEFAULT_BASE_URL = "https://api.laratranslate.com";
|
|
10
|
-
function create(accessKeyId, accessKeySecret, baseUrl) {
|
|
10
|
+
function create(accessKeyId, accessKeySecret, baseUrl, keepAlive) {
|
|
11
11
|
const url = new URL(baseUrl || DEFAULT_BASE_URL);
|
|
12
12
|
if (url.protocol !== "https:" && url.protocol !== "http:")
|
|
13
13
|
throw new TypeError(`Invalid URL (protocol): ${url.protocol}`);
|
|
@@ -19,5 +19,5 @@ function create(accessKeyId, accessKeySecret, baseUrl) {
|
|
|
19
19
|
if (typeof window !== "undefined")
|
|
20
20
|
return new browser_client_1.BrowserLaraClient(parsedURL, accessKeyId, accessKeySecret);
|
|
21
21
|
else
|
|
22
|
-
return new node_client_1.NodeLaraClient(parsedURL, accessKeyId, accessKeySecret);
|
|
22
|
+
return new node_client_1.NodeLaraClient(parsedURL, accessKeyId, accessKeySecret, keepAlive !== null && keepAlive !== void 0 ? keepAlive : true);
|
|
23
23
|
}
|
package/lib/net/node-client.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { type BaseURL, type ClientResponse, LaraClient, type MultiPartFile } fro
|
|
|
4
4
|
export declare class NodeLaraClient extends LaraClient {
|
|
5
5
|
private readonly baseUrl;
|
|
6
6
|
private readonly agent;
|
|
7
|
-
constructor(baseUrl: BaseURL, accessKeyId: string, accessKeySecret: string);
|
|
7
|
+
constructor(baseUrl: BaseURL, accessKeyId: string, accessKeySecret: string, keepAlive?: boolean);
|
|
8
8
|
protected send(path: string, headers: Record<string, string>, body?: Record<string, any>): Promise<ClientResponse>;
|
|
9
9
|
protected wrapMultiPartFile(file: MultiPartFile): Readable;
|
|
10
10
|
}
|
package/lib/net/node-client.js
CHANGED
|
@@ -12,10 +12,10 @@ const form_data_1 = __importDefault(require("form-data"));
|
|
|
12
12
|
const client_1 = require("./client");
|
|
13
13
|
/** @internal */
|
|
14
14
|
class NodeLaraClient extends client_1.LaraClient {
|
|
15
|
-
constructor(baseUrl, accessKeyId, accessKeySecret) {
|
|
15
|
+
constructor(baseUrl, accessKeyId, accessKeySecret, keepAlive = true) {
|
|
16
16
|
super(accessKeyId, accessKeySecret);
|
|
17
17
|
this.baseUrl = baseUrl;
|
|
18
|
-
this.agent = baseUrl.secure ? new node_https_1.default.Agent({ keepAlive
|
|
18
|
+
this.agent = baseUrl.secure ? new node_https_1.default.Agent({ keepAlive }) : new node_http_1.default.Agent({ keepAlive });
|
|
19
19
|
}
|
|
20
20
|
async send(path, headers, body) {
|
|
21
21
|
let requestBody;
|
|
@@ -71,15 +71,24 @@ class NodeLaraClient extends client_1.LaraClient {
|
|
|
71
71
|
json = JSON.parse(data);
|
|
72
72
|
}
|
|
73
73
|
catch (_e) {
|
|
74
|
-
reject(new SyntaxError("Invalid JSON response"));
|
|
74
|
+
return reject(new SyntaxError("Invalid JSON response"));
|
|
75
75
|
}
|
|
76
76
|
resolve({
|
|
77
77
|
statusCode: res.statusCode,
|
|
78
78
|
body: json
|
|
79
79
|
});
|
|
80
80
|
});
|
|
81
|
+
// close connection on error
|
|
82
|
+
res.on("error", (err) => {
|
|
83
|
+
req.destroy();
|
|
84
|
+
return reject(err);
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
// close connection on error
|
|
88
|
+
req.on("error", (err) => {
|
|
89
|
+
req.destroy();
|
|
90
|
+
return reject(err);
|
|
81
91
|
});
|
|
82
|
-
req.on("error", reject);
|
|
83
92
|
if (requestBody instanceof form_data_1.default) {
|
|
84
93
|
requestBody.pipe(req);
|
|
85
94
|
}
|
package/lib/net/s3/client.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Readable } from "node:stream";
|
|
2
|
-
import type { S3UploadFields } from "../../
|
|
2
|
+
import type { S3UploadFields } from "../../documents";
|
|
3
3
|
import type { MultiPartFile } from "../client";
|
|
4
4
|
import { S3Client } from "./client";
|
|
5
5
|
/** @internal */
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import type { Credentials } from "./credentials";
|
|
2
|
+
import { Documents } from "./documents";
|
|
3
|
+
import { Glossaries } from "./glossaries";
|
|
4
|
+
import { Memories } from "./memories";
|
|
5
|
+
import { type LaraClient } from "./net";
|
|
6
|
+
export type TranslatorOptions = {
|
|
7
|
+
serverUrl?: string;
|
|
8
|
+
keepAlive?: boolean;
|
|
9
|
+
};
|
|
10
|
+
export interface NGMemoryMatch {
|
|
11
|
+
memory: string;
|
|
12
|
+
tuid?: string;
|
|
13
|
+
language: [string, string];
|
|
14
|
+
sentence: string;
|
|
15
|
+
translation: string;
|
|
16
|
+
score: number;
|
|
17
|
+
}
|
|
18
|
+
export interface NGGlossaryMatch {
|
|
19
|
+
glossary: string;
|
|
20
|
+
language: [string, string];
|
|
21
|
+
term: string;
|
|
22
|
+
translation: string;
|
|
23
|
+
}
|
|
24
|
+
export interface TextBlock {
|
|
25
|
+
readonly text: string;
|
|
26
|
+
readonly translatable?: boolean;
|
|
27
|
+
}
|
|
28
|
+
export interface TextResult<T extends string | string[] | TextBlock[]> {
|
|
29
|
+
readonly contentType: string;
|
|
30
|
+
readonly sourceLanguage: string;
|
|
31
|
+
readonly translation: T;
|
|
32
|
+
readonly adaptedTo?: string[];
|
|
33
|
+
readonly glossaries?: string[];
|
|
34
|
+
readonly adaptedToMatches?: NGMemoryMatch[] | NGMemoryMatch[][];
|
|
35
|
+
readonly glossariesMatches?: NGGlossaryMatch[] | NGGlossaryMatch[][];
|
|
36
|
+
}
|
|
37
|
+
export type TranslateOptions = {
|
|
38
|
+
sourceHint?: string;
|
|
39
|
+
adaptTo?: string[];
|
|
40
|
+
instructions?: string[];
|
|
41
|
+
glossaries?: string[];
|
|
42
|
+
contentType?: string;
|
|
43
|
+
multiline?: boolean;
|
|
44
|
+
timeoutInMillis?: number;
|
|
45
|
+
priority?: "normal" | "background";
|
|
46
|
+
useCache?: boolean | "overwrite";
|
|
47
|
+
cacheTTLSeconds?: number;
|
|
48
|
+
noTrace?: boolean;
|
|
49
|
+
verbose?: boolean;
|
|
50
|
+
headers?: Record<string, string>;
|
|
51
|
+
style?: TranslationStyle;
|
|
52
|
+
};
|
|
53
|
+
export type TranslationStyle = "faithful" | "fluid" | "creative";
|
|
54
|
+
export interface DetectResult {
|
|
55
|
+
language: string;
|
|
56
|
+
contentType: string;
|
|
57
|
+
}
|
|
58
|
+
export declare class Translator {
|
|
59
|
+
protected readonly client: LaraClient;
|
|
60
|
+
readonly memories: Memories;
|
|
61
|
+
readonly documents: Documents;
|
|
62
|
+
readonly glossaries: Glossaries;
|
|
63
|
+
constructor(credentials: Credentials, options?: TranslatorOptions);
|
|
64
|
+
getLanguages(): Promise<string[]>;
|
|
65
|
+
translate<T extends string | string[] | TextBlock[]>(text: T, source: string | null, target: string, options?: TranslateOptions): Promise<TextResult<T>>;
|
|
66
|
+
detect(text: string | string[], hint?: string, passlist?: string[]): Promise<DetectResult>;
|
|
67
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
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 = void 0;
|
|
7
|
+
const documents_1 = require("./documents");
|
|
8
|
+
const glossaries_1 = require("./glossaries");
|
|
9
|
+
const memories_1 = require("./memories");
|
|
10
|
+
const net_1 = __importDefault(require("./net"));
|
|
11
|
+
class Translator {
|
|
12
|
+
constructor(credentials, options) {
|
|
13
|
+
this.client = (0, net_1.default)(credentials.accessKeyId, credentials.accessKeySecret, options === null || options === void 0 ? void 0 : options.serverUrl, options === null || options === void 0 ? void 0 : options.keepAlive);
|
|
14
|
+
this.memories = new memories_1.Memories(this.client);
|
|
15
|
+
this.documents = new documents_1.Documents(this.client);
|
|
16
|
+
this.glossaries = new glossaries_1.Glossaries(this.client);
|
|
17
|
+
}
|
|
18
|
+
async getLanguages() {
|
|
19
|
+
return await this.client.get("/languages");
|
|
20
|
+
}
|
|
21
|
+
async translate(text, source, target, options) {
|
|
22
|
+
const headers = {};
|
|
23
|
+
if (options === null || options === void 0 ? void 0 : options.headers) {
|
|
24
|
+
for (const [name, value] of Object.entries(options.headers)) {
|
|
25
|
+
headers[name] = value;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
if (options === null || options === void 0 ? void 0 : options.noTrace) {
|
|
29
|
+
headers["X-No-Trace"] = "true";
|
|
30
|
+
}
|
|
31
|
+
return await this.client.post("/translate", {
|
|
32
|
+
q: text,
|
|
33
|
+
source,
|
|
34
|
+
target,
|
|
35
|
+
source_hint: options === null || options === void 0 ? void 0 : options.sourceHint,
|
|
36
|
+
content_type: options === null || options === void 0 ? void 0 : options.contentType,
|
|
37
|
+
multiline: (options === null || options === void 0 ? void 0 : options.multiline) !== false,
|
|
38
|
+
adapt_to: options === null || options === void 0 ? void 0 : options.adaptTo,
|
|
39
|
+
glossaries: options === null || options === void 0 ? void 0 : options.glossaries,
|
|
40
|
+
instructions: options === null || options === void 0 ? void 0 : options.instructions,
|
|
41
|
+
timeout: options === null || options === void 0 ? void 0 : options.timeoutInMillis,
|
|
42
|
+
priority: options === null || options === void 0 ? void 0 : options.priority,
|
|
43
|
+
use_cache: options === null || options === void 0 ? void 0 : options.useCache,
|
|
44
|
+
cache_ttl: options === null || options === void 0 ? void 0 : options.cacheTTLSeconds,
|
|
45
|
+
verbose: options === null || options === void 0 ? void 0 : options.verbose,
|
|
46
|
+
style: options === null || options === void 0 ? void 0 : options.style
|
|
47
|
+
}, undefined, headers);
|
|
48
|
+
}
|
|
49
|
+
async detect(text, hint, passlist) {
|
|
50
|
+
return await this.client.post("/detect", {
|
|
51
|
+
q: text,
|
|
52
|
+
hint,
|
|
53
|
+
passlist
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
exports.Translator = Translator;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const version = "1.7.1";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@translated/lara",
|
|
3
|
-
"version": "1.7.
|
|
3
|
+
"version": "1.7.1",
|
|
4
4
|
"main": "lib/index.js",
|
|
5
5
|
"types": "lib/index.d.ts",
|
|
6
6
|
"engines": {
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
},
|
|
9
9
|
"scripts": {
|
|
10
10
|
"build": "rm -rf lib/* lib-browser/* && node scripts/generate-sdk-version.js && tsc && webpack",
|
|
11
|
-
"version": "node scripts/generate-sdk-version.js && git add src/sdk-version.ts",
|
|
11
|
+
"version": "node scripts/generate-sdk-version.js && git add src/utils/sdk-version.ts",
|
|
12
12
|
"biome:check": "biome check",
|
|
13
13
|
"biome:write": "biome check --write"
|
|
14
14
|
},
|
package/lib/sdk-version.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const version = "1.7.0";
|
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
export interface Memory {
|
|
2
|
-
readonly id: string;
|
|
3
|
-
readonly createdAt: Date;
|
|
4
|
-
readonly updatedAt: Date;
|
|
5
|
-
readonly sharedAt: Date;
|
|
6
|
-
readonly name: string;
|
|
7
|
-
readonly externalId?: string;
|
|
8
|
-
readonly secret?: string;
|
|
9
|
-
readonly ownerId: string;
|
|
10
|
-
readonly collaboratorsCount: number;
|
|
11
|
-
}
|
|
12
|
-
export interface MemoryImport {
|
|
13
|
-
readonly id: string;
|
|
14
|
-
readonly begin: number;
|
|
15
|
-
readonly end: number;
|
|
16
|
-
readonly channel: number;
|
|
17
|
-
readonly size: number;
|
|
18
|
-
readonly progress: number;
|
|
19
|
-
}
|
|
20
|
-
export declare enum DocumentStatus {
|
|
21
|
-
INITIALIZED = "initialized",// just been created
|
|
22
|
-
ANALYZING = "analyzing",// being analyzed for language detection and chars count
|
|
23
|
-
PAUSED = "paused",// paused after analysis, needs user confirm
|
|
24
|
-
READY = "ready",// ready to be translated
|
|
25
|
-
TRANSLATING = "translating",
|
|
26
|
-
TRANSLATED = "translated",
|
|
27
|
-
ERROR = "error"
|
|
28
|
-
}
|
|
29
|
-
export interface DocxExtractionParams {
|
|
30
|
-
extractComments?: boolean;
|
|
31
|
-
acceptRevisions?: boolean;
|
|
32
|
-
}
|
|
33
|
-
export type DocumentOptions = {
|
|
34
|
-
adaptTo?: string[];
|
|
35
|
-
glossaries?: string[];
|
|
36
|
-
noTrace?: boolean;
|
|
37
|
-
style?: TranslationStyle;
|
|
38
|
-
};
|
|
39
|
-
export type DocumentDownloadOptions = {
|
|
40
|
-
outputFormat?: string;
|
|
41
|
-
};
|
|
42
|
-
export type DocumentUploadOptions = DocumentOptions & {
|
|
43
|
-
password?: string;
|
|
44
|
-
extractionParams?: DocxExtractionParams;
|
|
45
|
-
};
|
|
46
|
-
export interface Document {
|
|
47
|
-
readonly id: string;
|
|
48
|
-
readonly status: DocumentStatus;
|
|
49
|
-
readonly source?: string;
|
|
50
|
-
readonly target: string;
|
|
51
|
-
readonly filename: string;
|
|
52
|
-
readonly createdAt: Date;
|
|
53
|
-
readonly updatedAt: Date;
|
|
54
|
-
readonly options?: DocumentOptions;
|
|
55
|
-
readonly translatedChars?: number;
|
|
56
|
-
readonly totalChars?: number;
|
|
57
|
-
readonly errorReason?: string;
|
|
58
|
-
}
|
|
59
|
-
export interface TextBlock {
|
|
60
|
-
readonly text: string;
|
|
61
|
-
readonly translatable?: boolean;
|
|
62
|
-
}
|
|
63
|
-
export interface NGMemoryMatch {
|
|
64
|
-
memory: string;
|
|
65
|
-
tuid?: string;
|
|
66
|
-
language: [string, string];
|
|
67
|
-
sentence: string;
|
|
68
|
-
translation: string;
|
|
69
|
-
score: number;
|
|
70
|
-
}
|
|
71
|
-
export interface NGGlossaryMatch {
|
|
72
|
-
glossary: string;
|
|
73
|
-
language: [string, string];
|
|
74
|
-
term: string;
|
|
75
|
-
translation: string;
|
|
76
|
-
}
|
|
77
|
-
export interface TextResult<T extends string | string[] | TextBlock[]> {
|
|
78
|
-
readonly contentType: string;
|
|
79
|
-
readonly sourceLanguage: string;
|
|
80
|
-
readonly translation: T;
|
|
81
|
-
readonly adaptedTo?: string[];
|
|
82
|
-
readonly glossaries?: string[];
|
|
83
|
-
readonly adaptedToMatches?: NGMemoryMatch[] | NGMemoryMatch[][];
|
|
84
|
-
readonly glossariesMatches?: NGGlossaryMatch[] | NGGlossaryMatch[][];
|
|
85
|
-
}
|
|
86
|
-
export interface DetectResult {
|
|
87
|
-
language: string;
|
|
88
|
-
contentType: string;
|
|
89
|
-
}
|
|
90
|
-
export interface Glossary {
|
|
91
|
-
readonly id: string;
|
|
92
|
-
readonly name: string;
|
|
93
|
-
readonly ownerId: string;
|
|
94
|
-
readonly createdAt: Date;
|
|
95
|
-
readonly updatedAt: Date;
|
|
96
|
-
}
|
|
97
|
-
export interface GlossaryImport {
|
|
98
|
-
readonly id: string;
|
|
99
|
-
readonly begin: number;
|
|
100
|
-
readonly end: number;
|
|
101
|
-
readonly channel: number;
|
|
102
|
-
readonly size: number;
|
|
103
|
-
readonly progress: number;
|
|
104
|
-
}
|
|
105
|
-
export interface GlossaryCounts {
|
|
106
|
-
unidirectional?: Record<string, number>;
|
|
107
|
-
multidirectional?: number;
|
|
108
|
-
}
|
|
109
|
-
export type TranslationStyle = "faithful" | "fluid" | "creative";
|
package/lib/translator/models.js
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DocumentStatus = void 0;
|
|
4
|
-
// biome-ignore format: keep comments aligned
|
|
5
|
-
var DocumentStatus;
|
|
6
|
-
(function (DocumentStatus) {
|
|
7
|
-
DocumentStatus["INITIALIZED"] = "initialized";
|
|
8
|
-
DocumentStatus["ANALYZING"] = "analyzing";
|
|
9
|
-
DocumentStatus["PAUSED"] = "paused";
|
|
10
|
-
DocumentStatus["READY"] = "ready";
|
|
11
|
-
DocumentStatus["TRANSLATING"] = "translating";
|
|
12
|
-
DocumentStatus["TRANSLATED"] = "translated";
|
|
13
|
-
DocumentStatus["ERROR"] = "error";
|
|
14
|
-
})(DocumentStatus || (exports.DocumentStatus = DocumentStatus = {}));
|
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
import type { Credentials } from "../credentials";
|
|
2
|
-
import { type LaraClient } from "../net";
|
|
3
|
-
import type { MultiPartFile } from "../net/client";
|
|
4
|
-
import { type DetectResult, type Document, type DocumentDownloadOptions, type DocumentUploadOptions, type Glossary, type GlossaryCounts, type GlossaryImport, type Memory, type MemoryImport, type TextBlock, type TextResult, type TranslationStyle } from "./models";
|
|
5
|
-
export type TranslatorOptions = {
|
|
6
|
-
serverUrl?: string;
|
|
7
|
-
};
|
|
8
|
-
export type MemoryImportCallback = (memoryImport: MemoryImport) => void;
|
|
9
|
-
export declare class Memories {
|
|
10
|
-
private readonly client;
|
|
11
|
-
private readonly pollingInterval;
|
|
12
|
-
constructor(client: LaraClient);
|
|
13
|
-
list(): Promise<Memory[]>;
|
|
14
|
-
create(name: string, externalId?: string): Promise<Memory>;
|
|
15
|
-
get(id: string): Promise<Memory | null>;
|
|
16
|
-
delete(id: string): Promise<Memory>;
|
|
17
|
-
update(id: string, name: string): Promise<Memory>;
|
|
18
|
-
connect<T extends string | string[]>(ids: T): Promise<T extends string ? Memory : Memory[]>;
|
|
19
|
-
importTmx(id: string, tmx: MultiPartFile, gzip?: boolean): Promise<MemoryImport>;
|
|
20
|
-
addTranslation(id: string | string[], source: string, target: string, sentence: string, translation: string, tuid?: string, sentenceBefore?: string, sentenceAfter?: string, headers?: Record<string, string>): Promise<MemoryImport>;
|
|
21
|
-
deleteTranslation(id: string | string[], source: string, target: string, sentence?: string, translation?: string, tuid?: string, sentenceBefore?: string, sentenceAfter?: string): Promise<MemoryImport>;
|
|
22
|
-
getImportStatus(id: string): Promise<MemoryImport>;
|
|
23
|
-
waitForImport(mImport: MemoryImport, updateCallback?: MemoryImportCallback, maxWaitTime?: number): Promise<MemoryImport>;
|
|
24
|
-
}
|
|
25
|
-
export type TranslateOptions = {
|
|
26
|
-
sourceHint?: string;
|
|
27
|
-
adaptTo?: string[];
|
|
28
|
-
instructions?: string[];
|
|
29
|
-
glossaries?: string[];
|
|
30
|
-
contentType?: string;
|
|
31
|
-
multiline?: boolean;
|
|
32
|
-
timeoutInMillis?: number;
|
|
33
|
-
priority?: "normal" | "background";
|
|
34
|
-
useCache?: boolean | "overwrite";
|
|
35
|
-
cacheTTLSeconds?: number;
|
|
36
|
-
noTrace?: boolean;
|
|
37
|
-
verbose?: boolean;
|
|
38
|
-
headers?: Record<string, string>;
|
|
39
|
-
style?: TranslationStyle;
|
|
40
|
-
};
|
|
41
|
-
export type DocumentTranslateOptions = DocumentUploadOptions & DocumentDownloadOptions;
|
|
42
|
-
export type S3UploadFields = {
|
|
43
|
-
acl: string;
|
|
44
|
-
bucket: string;
|
|
45
|
-
key: string;
|
|
46
|
-
};
|
|
47
|
-
export declare class Documents {
|
|
48
|
-
private readonly client;
|
|
49
|
-
private readonly s3Client;
|
|
50
|
-
constructor(client: LaraClient);
|
|
51
|
-
upload(file: MultiPartFile, filename: string, source: string | null, target: string, options?: DocumentUploadOptions): Promise<Document>;
|
|
52
|
-
status(id: string): Promise<Document>;
|
|
53
|
-
download(id: string, options?: DocumentDownloadOptions): Promise<Blob | Buffer>;
|
|
54
|
-
translate(file: MultiPartFile, filename: string, source: string | null, target: string, options?: DocumentTranslateOptions): Promise<Blob | Buffer>;
|
|
55
|
-
}
|
|
56
|
-
export type GlossaryImportCallback = (glossaryImport: GlossaryImport) => void;
|
|
57
|
-
export declare class Glossaries {
|
|
58
|
-
private readonly client;
|
|
59
|
-
private readonly pollingInterval;
|
|
60
|
-
constructor(client: LaraClient);
|
|
61
|
-
list(): Promise<Glossary[]>;
|
|
62
|
-
create(name: string): Promise<Glossary>;
|
|
63
|
-
get(id: string): Promise<Glossary | null>;
|
|
64
|
-
delete(id: string): Promise<Glossary>;
|
|
65
|
-
update(id: string, name: string): Promise<Glossary>;
|
|
66
|
-
importCsv(id: string, csv: MultiPartFile, gzip?: boolean): Promise<GlossaryImport>;
|
|
67
|
-
getImportStatus(id: string): Promise<GlossaryImport>;
|
|
68
|
-
waitForImport(gImport: GlossaryImport, updateCallback?: GlossaryImportCallback, maxWaitTime?: number): Promise<GlossaryImport>;
|
|
69
|
-
counts(id: string): Promise<GlossaryCounts>;
|
|
70
|
-
export(id: string, contentType: "csv/table-uni", source?: string): Promise<string>;
|
|
71
|
-
}
|
|
72
|
-
export declare class Translator {
|
|
73
|
-
protected readonly client: LaraClient;
|
|
74
|
-
readonly memories: Memories;
|
|
75
|
-
readonly documents: Documents;
|
|
76
|
-
readonly glossaries: Glossaries;
|
|
77
|
-
constructor(credentials: Credentials, options?: TranslatorOptions);
|
|
78
|
-
getLanguages(): Promise<string[]>;
|
|
79
|
-
translate<T extends string | string[] | TextBlock[]>(text: T, source: string | null, target: string, options?: TranslateOptions): Promise<TextResult<T>>;
|
|
80
|
-
detect(text: string | string[], hint?: string, passlist?: string[]): Promise<DetectResult>;
|
|
81
|
-
}
|
|
@@ -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
|