class LingvaTranslator { // URL of your instance of LingvaTranslate apiPath = "https://lingva.ml"; translate = (text, from, to) => { return fetch(`${this.apiPath}/api/v1/${from}/${to}/${text}`, { credentials: "omit", headers: { "User-Agent": "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:99.0) Gecko/20100101 Firefox/99.0", Accept: "*/*", "Accept-Language": "en-US,en;q=0.5", "Sec-Fetch-Dest": "empty", "Sec-Fetch-Mode": "cors", "Sec-Fetch-Site": "same-origin" }, method: "GET", mode: "cors", }) .then((r) => r.json()) .then(({ translation }) => translation); }; translateBatch = (texts, from, to) => Promise.all(texts.map((text) => this.translate(text, from, to))); getLengthLimit = () => 4000; getRequestsTimeout = () => 300; checkLimitExceeding = (text) => { const textLength = !Array.isArray(text) ? text.length : text.reduce((len, text) => len + text.length, 0); return textLength - this.getLengthLimit(); } static isSupportedAutoFrom = () => true; static getSupportedLanguages = () => [ "en", "ar", "az", "zh", "cs", "nl", "eo", "fi", "fr", "de", "el", "hi", "hu", "id", "ga", "it", "ja", "ko", "fa", "pl", "pt", "ru", "sk", "es", "sv", "tr", "uk", "vi" ]; } LingvaTranslator;