UNPKG

@memori.ai/memori-react

Version:

[![npm version](https://img.shields.io/github/package-json/v/memori-ai/memori-react)](https://www.npmjs.com/package/@memori.ai/memori-react) ![Tests](https://github.com/memori-ai/memori-react/workflows/CI/badge.svg?branch=main) ![TypeScript Support](https

40 lines 1.46 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getTranslation = exports.dialogKeywords = void 0; exports.dialogKeywords = [ 'va bene', 'no grazie', 'si', 'no', 'sì', 'arrivederci', "non c'entrava", 'non mi è piaciuto', ]; const stripOutputTags = (text) => { return text.replaceAll(/<output.*?>(.*?)<\/output>/g, ''); }; const getTranslation = async (text, to, from, baseUrl) => { var _a; let textToTranslate = stripOutputTags(text); const isReservedKeyword = exports.dialogKeywords.indexOf(text.toLowerCase()) > -1; const fromLanguage = isReservedKeyword ? 'IT' : from === null || from === void 0 ? void 0 : from.toUpperCase(); const toLanguage = to.toUpperCase(); const deeplResult = await fetch(`${baseUrl || 'https://www.aisuru.com'}/api/translate`, { cache: 'no-cache', method: 'POST', body: JSON.stringify({ text: textToTranslate, target_lang: toLanguage, source_lang: fromLanguage, }), headers: { Accept: '*/*', 'Content-Type': 'application/json', }, }); const deeplResponse = await deeplResult.json(); return (_a = deeplResponse === null || deeplResponse === void 0 ? void 0 : deeplResponse.translations) === null || _a === void 0 ? void 0 : _a[0]; }; exports.getTranslation = getTranslation; //# sourceMappingURL=translations.js.map