-
-
Notifications
You must be signed in to change notification settings - Fork 120
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
Nonsense generated for haw (wrong translation) #70
Comments
The random nonsense may be because the server doesn't receive a required header called |
@plainheart Nice investigation! I can confirm this. With |
I forked this repo and added two new endpoints that can work better than the current website endpoint. But I still hope the algorithm of the header could be figured out. |
I generated an It seems that we can at least use puppeteer + cache method for it if it's hard to extract the algorithm. |
I ever dug into the source code, the header value may be related to the query string, if we changed the query string, it should be invalid immediately theoretically. Does it still work for you with the text different from the previous? |
Yes.. You were right. It's generated from the query string. It won't work if I changed my text. Yes... So we have to extract the algorithm then. |
How did you generate an X-Goog-BatchExecute-Bgr,Thank you! |
Thank for the research! |
@vitalets Hi, thanks for your reply.
No. I'm not sure if the other languages have the same issue. But I can confirm it is existing in Chinese(zh).
Please refer to #71. Though the translation result is correct generally, there are many unexpected mixed upper-case and lower-case letters in sentences, which affects the normal reading. Besides, the translation looks close by sense, but it has many small grammar issues comparing to the website. Everything would be okay if a valid value for the header |
Yeah( Google protects the batch API from such access. |
@vitalets I currently use your here is an example of the translate.googleapis.com/translate_a/single/ url I also found that this library google-translate-open-api uses const translateOpenApi = require('google-translate-open-api');
translateOpenApi.default(`some text`, {
client: "dict-chrome-ex",
to: 'en'
}).then(result => {
const translatedText = result.data.sentences.map(s => s.trans).join('');
var formattedResult = {
text: translatedText,
from :{
language: { iso: result.data.src }
}
}
console.log(formattedResult)
}) Hope this helps and gets integrated in into |
That is true for the moment, however I suspect Google will soon turn that off in favor of their new RPC method |
For anyone who wants an accurate translation: I have an alternative solution using the Puppeteer to scrape result directly: https://github.com/Songkeys/Translateer. It needs more resources (due to the Puppeteer, you know) and perhaps slower ( |
Good approach. Will add to readme. |
Anyone who looking accurate translate can use that code. That code uses another google translate route for translate and has the same translation result as the website. |
It shows that "TypeError: Cannot read properties of undefined (reading 'map')". |
Is there any active solution on the incorrect translations? I am very curious if someone has an solution to the problem. |
any update? thanks |
I've found it's related to your client IP however, from my real IP unproxied autocorrect fails in some cases(without |
|
Hey everyone! New version is available on npm as
Original text of this issue is translated correctly: import { translate } from '@vitalets/google-translate-api';
const { text } = await translate('Ia hala ana mai o ka waa o Pele, ia wa i hoouna mai ai o Kahinalii ka makuahine, i ke kai hoee nui a ka launa ole, a lewa ana ka waa o Honuaiakea iluna o ka halehale hanupanupa kuhoho a kawehaweha o ke kai. Ua huahuai ae la na mapuna o ke kai ma lalo ae o ka papaku o ka moana, hakikili ka ua mai ka lani mai. Olaolapa ka uwela i ka lewa uli, nakolokolo ikuwa ka leo papaaina o ka hekili, huikau ka lewa nuu, ka lewa lalo. Auwe! He ino!!');
console.log(text); Output:
Also I've removed all outdated and vulnerable dependencies, added support of react-native and rewritten in typescript. I will appreciate if you install and check this beta version in your scenarios and share the feedback here. If everything is ok, I'm ready to release it as main version. Please note that new version shape is uncompatible with previous one. Thanks in advance! @avisitor |
const translate = require('@vitalets/google-translate-api');
var text = 'Ia hala ana mai o ka waa o Pele, ia wa i hoouna mai ai o Kahinalii ka makuahine, i ke kai hoee nui a ka launa ole, a lewa ana ka waa o Honuaiakea iluna o ka halehale hanupanupa kuhoho a kawehaweha o ke kai. Ua huahuai ae la na mapuna o ke kai ma lalo ae o ka papaku o ka moana, hakikili ka ua mai ka lani mai. Olaolapa ka uwela i ka lewa uli, nakolokolo ikuwa ka leo papaaina o ka hekili, huikau ka lewa nuu, ka lewa lalo. Auwe! He ino!!';
translate(text, {from: 'haw', to: 'en'}).then(res => {
console.log(res.text);
//console.log(res.from.language.iso);
}).catch(err => {
console.error(err);
});
$ node translate.js
The youngest birdmen came to whom there, the whole drivenaka had ate fish, and in the land of the sea Shell.All the board of the sea of the sea became the bottom of the sea floor, the feature of the sky.The air, Do otherwise social, Judge Mount Hords, communions to the air Nuunu.Wow!Is a bad !!
When pasted into translate.google.com:
When Pele's canoe passed, the mother sent Kahinalii to paddle a great and incompatible paddle, and the canoe from Honuaiakea flew over the mysterious building and the depths of the sea. The waves of the sea poured forth beneath the sea floor, and the rain from heaven thundered. The lightning flashed in the dark sky, the table sound of thunder roared, the sky above and the sky below were confused. Alas! It's bad !!
The text was updated successfully, but these errors were encountered: