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

[v5] batch-style still has a text limit of 5000 chars

Open Songkeys opened this issue 3 years ago • 4 comments

There is still a text limit in batch-style RPC mode from v5.

If the character length exceeds 5000 characters, an error will occur:

TypeError: Cannot read property '1' of null
Url: https://translate.google.com/_/TranslateWebserverUi/data/batchexecute?rpcids=MkEWBc&f.sid=3349740657455987534&bl=boq_translate-webserver_20210128.12_p0&hl=en-US&soc-app=1&soc-platform=1&soc-device=1&_reqid=9513&rt=c
    at ....../node_modules/@vitalets/google-translate-api/index.js:90:21
    at processTicksAndRejections (internal/process/task_queues.js:93:5) {
  code: 'BAD_NETWORK'
}

It happens with this line: https://github.com/vitalets/google-translate-api/blob/bba16050aea60232b510da0646c61ff953ca2f23/index.js#L90

Songkeys avatar Feb 01 '21 07:02 Songkeys

It seems this is a restriction of Google translation API itself. Could you try splitting text by chunks as suggested in https://github.com/vitalets/google-translate-api/issues/20?

vitalets avatar Feb 07 '21 08:02 vitalets

Yes. Splitting text does solve the problem. The previous implementation allows only around 3000 characters. And the new one is 5000, which is also the one of web version. Seems reasonable. I take it this new batch-style just adds up another 2000 of limit? Is there any other difference?

Songkeys avatar Feb 07 '21 09:02 Songkeys

@Songkeys I think we can only check differences on practice. As I didn't find any docs on this RPC API and current implementation was reverse engIneered in this article.

Anyway, I've added note about maximum text length to readme. Thanks!

vitalets avatar Feb 08 '21 07:02 vitalets

In the website, there is a pagination system splitting each 5000 chars

"5,000 character limit. Use the arrows to translate more"

I think this is the hard limit.

vkedwardli avatar Feb 16 '21 18:02 vkedwardli