-
Notifications
You must be signed in to change notification settings - Fork 5
Open
Description
Hi, I have written a translator which uses Mymemory api but, I get result as undefined. :
class MyMemoryTranslator {
translate = (text, from, to) => {
// Set MyMemory API parameters
const url = "https://api.mymemory.translated.net/get";
const from1 = from;
const to1 = to;
const params = new URLSearchParams({
q: text,
de: "[email protected]"
});
// Send request to MyMemory API
fetch(`${url}?${params}&langpair=${from1}|${to1}`)
.then(response => response.json())
.then(data => {
// Get translated text from response
const translatedText = data.responseData.translatedText;
translatedText;
});
}
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 isSupportedLanguage(language) {
return MyMemoryTranslator.supportedLanguages.includes(language);
}
static getSupportedLanguages() {
return [
"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"
];
}
static isSupportedAutoFrom() {
return false;
}
}
MyMemoryTranslator;
Metadata
Metadata
Assignees
Labels
No labels