Frully / html-google-translate

Translate HTML with Google Translate and maintain the original structures of sentences and HTML.
9 stars 4 forks source link

UnhandledPromiseRejectionWarning: Error: Cannot get TKK #1

Open h4xhor opened 2 years ago

h4xhor commented 2 years ago

Hi Frully, thanks for creating this repo.

I have an issue. So what I did was:

npm install html-google-translate --save

Then I have this code:

const translate = require('html-google-translate');

async function testTransHtml() {    
  const html = '<p><i>I</i> love <a href="#">you</a>!</p>'    

  const transHtml = await translate(html, {    
    from: 'en',                                                                                            
    to: 'es',    
  })    
}    

testTransHtml();

When I run it I get this error:

(node:92502) UnhandledPromiseRejectionWarning: Error: Cannot get TKK.
    at /home/sum/sum/progs/js/node_modules/@frully/google-translate-open-api/dist/token.js:116:31
    at step (/home/sum/sum/progs/js/node_modules/@frully/google-translate-open-api/dist/token.js:44:23)
    at Object.next (/home/sum/sum/progs/js/node_modules/@frully/google-translate-open-api/dist/token.js:25:53)
    at fulfilled (/home/sum/sum/progs/js/node_modules/@frully/google-translate-open-api/dist/token.js:16:58)
    at processTicksAndRejections (internal/process/task_queues.js:95:5)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:92502) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:92502) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

Any help greatly appreciated.

CrazyH2 commented 1 year ago

Same @Frully

milahu commented 11 months ago
$ grep -r 'Cannot get TKK.' node_modules/
node_modules/.pnpm/@frully+google-translate-open-api@1.4.3/node_modules/@frully/google-translate-open-api/dist/token.js:                        throw new Error('Cannot get TKK.');

so this is an upstream issue in Frully/google-translate-open-api

the parent project hua1995116/google-translate-open-api fails with http 403: https://github.com/hua1995116/google-translate-open-api/issues/22

a similar project matheuss/google-translate-api also fails with http 403: https://github.com/matheuss/google-translate-api/issues/79

... all these projects are outdated

these may work better: