UNPKG

@translated/lara

Version:

Official Lara SDK for JavaScript and Node.js

68 lines (67 loc) 2.23 kB
import type { Credentials } from "./credentials"; import { Documents } from "./documents"; import { Glossaries } from "./glossaries"; import { Memories } from "./memories"; import { type LaraClient } from "./net"; export type TranslatorOptions = { serverUrl?: string; keepAlive?: boolean; }; export interface NGMemoryMatch { memory: string; tuid?: string; language: [string, string]; sentence: string; translation: string; score: number; } export interface NGGlossaryMatch { glossary: string; language: [string, string]; term: string; translation: string; } export interface TextBlock { readonly text: string; readonly translatable?: boolean; } export interface TextResult<T extends string | string[] | TextBlock[]> { readonly contentType: string; readonly sourceLanguage: string; readonly translation: T; readonly adaptedTo?: string[]; readonly glossaries?: string[]; readonly adaptedToMatches?: NGMemoryMatch[] | NGMemoryMatch[][]; readonly glossariesMatches?: NGGlossaryMatch[] | NGGlossaryMatch[][]; } export type TranslateOptions = { sourceHint?: string; adaptTo?: string[]; instructions?: string[]; glossaries?: string[]; contentType?: string; multiline?: boolean; timeoutInMillis?: number; priority?: "normal" | "background"; useCache?: boolean | "overwrite"; cacheTTLSeconds?: number; noTrace?: boolean; verbose?: boolean; headers?: Record<string, string>; style?: TranslationStyle; }; export type TranslationStyle = "faithful" | "fluid" | "creative"; export interface DetectResult { language: string; contentType: string; } export declare class Translator { protected readonly client: LaraClient; readonly memories: Memories; readonly documents: Documents; readonly glossaries: Glossaries; constructor(credentials: Credentials, options?: TranslatorOptions); getLanguages(): Promise<string[]>; translate<T extends string | string[] | TextBlock[]>(text: T, source: string | null, target: string, options?: TranslateOptions): Promise<TextResult<T>>; detect(text: string | string[], hint?: string, passlist?: string[]): Promise<DetectResult>; }