UNPKG

@translated/lara

Version:

Official Lara SDK for JavaScript and Node.js

58 lines (57 loc) 2.92 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.Translator = void 0; const documents_1 = require("./documents"); const glossaries_1 = require("./glossaries"); const memories_1 = require("./memories"); const net_1 = __importDefault(require("./net")); class Translator { constructor(credentials, options) { 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); this.memories = new memories_1.Memories(this.client); this.documents = new documents_1.Documents(this.client); this.glossaries = new glossaries_1.Glossaries(this.client); } async getLanguages() { return await this.client.get("/languages"); } async translate(text, source, target, options) { const headers = {}; if (options === null || options === void 0 ? void 0 : options.headers) { for (const [name, value] of Object.entries(options.headers)) { headers[name] = value; } } if (options === null || options === void 0 ? void 0 : options.noTrace) { headers["X-No-Trace"] = "true"; } return await this.client.post("/translate", { q: text, source, target, source_hint: options === null || options === void 0 ? void 0 : options.sourceHint, content_type: options === null || options === void 0 ? void 0 : options.contentType, multiline: (options === null || options === void 0 ? void 0 : options.multiline) !== false, 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, timeout: options === null || options === void 0 ? void 0 : options.timeoutInMillis, priority: options === null || options === void 0 ? void 0 : options.priority, use_cache: options === null || options === void 0 ? void 0 : options.useCache, cache_ttl: options === null || options === void 0 ? void 0 : options.cacheTTLSeconds, verbose: options === null || options === void 0 ? void 0 : options.verbose, style: options === null || options === void 0 ? void 0 : options.style }, undefined, headers); } async detect(text, hint, passlist) { return await this.client.post("/detect", { q: text, hint, passlist }); } } exports.Translator = Translator;