Closed taishi55 closed 1 year ago
I tried to figure out how to make a request using POST. And it seems possible. This example worked for me.
const traslateToEng = async (sourceText) => {
const encodedValue = encodeURIComponent(`[[["MkEWBc","[[\\"${sourceText}\\",\\"ru\\",\\"en\\",true],[1]]",null,"generic"]]]`);
return axios({
method: 'POST',
headers: {'content-type': 'application/x-www-form-urlencoded'},
data: `f.req=${encodedValue}&`,
url: 'https://translate.google.com/_/TranslateWebserverUi/data/batchexecute?hl=en-US',
})
};
traslateToEng('Привет').then((result) => {
console.log(JSON.parse(result.data.replace(')]}\'', '').trim()));
});
But there is still a lot of work. Сurrent functions don't work very well for this example.
It looks perfect to me haha. What is the sM function doing in your current repo? I really wonder what it does
sM generates necessary token. Here is the repo sM is based on. https://github.com/matheuss/google-translate-token
I've updated the library. Try to use alpha version that uses POST requests.
npm install google-translate-api-browser@alpha
I tested it with this example https://github.com/cjvnjde/google-translate-api-browser/tree/v4.0.6-alpha/examples/server
But I'm not sure about the reliability of this version.
Thank you for the update. I will look into that. I got it! I will try to test if I can apply the approach to DeepL.
But I'm not sure about the reliability of this version.
Error when using in Node
translate(string, {to: lang}) .then(res => { console.log(res.text) }) .catch(err => { console.error(err); });
But I'm not sure about the reliability of this version.
Error when using in Node
translate(string, {to: lang}) .then(res => { console.log(res.text) }) .catch(err => { console.error(err); });
Google has changed the structure of the response. In version 4.1 it should work.
Post requests should also work.
The maximum number of letter seems roughly 1850 per request.
Is it possible to add a POST request to increase the input text to 5000?
This is my suggestion below. (It didn't work sadly)