google-translate-api icon indicating copy to clipboard operation
google-translate-api copied to clipboard

China doesn't work: Default URL banned, no proxy support, alternate URL not working

Open globalcitizen opened this issue 6 years ago • 3 comments

In China the regular page is banned, normally we have to use translate.google.cn instead.

No URL spec option There doesn't seem to be an option to redirect the queries to a new URL (China's is probably the only meaningful one out there).

I tried manually modifying the URL in my version of the library but it didn't work. Unfamiliar with node debugging so unsure how to get low level HTTP response information. However, this is what it looks like from a browser.

google-translate-china

No proxy option I looked for a proxy option but apparently that doesn't exit either. I also tried setting the standard unix environment variables: proxy, http_proxy, https_proxy, proxy_all, etc. but none appeared to take effect.

globalcitizen avatar Mar 19 '18 02:03 globalcitizen

you can change the request url translate.google.com to translate.google.cn. or you can install the package google-translate-api-cn by npm install --save google-translate-api-cn.

mack-wang avatar May 12 '18 14:05 mack-wang

This has been fixed in a better manner in https://github.com/vitalets/google-translate-api as of the writing of this comment.

rawr51919 avatar Mar 18 '19 16:03 rawr51919

Released yesterday @vitalets/google-translate-api where with help of @coltongit we can use custom tld for google translate host:

const translate = require('@vitalets/google-translate-api');

translate('Ik spreek Engels', {to: 'en', tld: 'cn'}).then(res => { ... }); 
// sends request to translate.google.cn

vitalets avatar Mar 19 '19 10:03 vitalets