UNPKG

anylang

Version:

A translator's kit that uses the free APIs of Google Translate, Yandex, Bing, ChatGPT, and other LLMs

46 lines (45 loc) 1.63 kB
import { Fetcher } from '../utils/fetcher/types'; import { TranslatorInstanceMembers } from './Translator'; export type TranslatorOptions<O extends Record<string, unknown> = {}> = O & { /** * API endpoint URL */ apiHost?: string; /** * Access key for requests to translator API */ apiKey?: string; /** * Union text array to 1 request (or more, but less than usualy anyway). * * Option for reduce the number of requests, but it can make artefacts in translated text. * * Some modules may not support this feature. */ useMultiplexing?: boolean; /** * Additional headers for requests */ headers?: Record<string, string>; /** * Custom fetcher */ fetcher?: Fetcher; }; /** * Basic abstract class for translator */ export declare abstract class BaseTranslator<C extends Record<string, unknown> = {}> implements TranslatorInstanceMembers { static readonly translatorName: string; static isRequiredKey: () => boolean; static isSupportedAutoFrom: () => boolean; static getSupportedLanguages: () => string[]; abstract getLengthLimit(): number; abstract getRequestsTimeout(): number; protected readonly options: TranslatorOptions<C>; constructor(options?: TranslatorOptions<C>); abstract translate(text: string, sourceLanguage: string, targetLanguage: string): Promise<string>; abstract translateBatch(text: string[], sourceLanguage: string, targetLanguage: string): Promise<(string | null)[]>; checkLimitExceeding(text: string | string[]): number; protected fetch: Fetcher; }