-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding support for MyMemory Translators #2
Comments
class MyMemoryTranslator {
apiPath = 'https://api.mymemory.translated.net/get';
translate = (text, from, to) => {
return fetch(`${this.apiPath}?q=${text}&langpair=${from}|${to}`, {
credentials: 'omit',
headers: {
'User-Agent':
'Mozilla/5.0 (X11; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/114.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(({ responseData }) => responseData.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 isSupportedAutoFrom = () => true;
// prettier-ignore
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"
];
}
MyMemoryTranslator; |
Thank you so much @AlphaBack for taking the time to solve this issue. Now it is working. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi, I have written a translator which uses Mymemory api but, I get result as undefined. :
The text was updated successfully, but these errors were encountered: