Rewrite GoogleTranslator.translate_batch method to require only one API call for the whole list of words (batch)
#248
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I noticed that it's possible to take advantage of the fact that Google Translate can handle multiple words at a time to speed up the
translate_batchmethod. In this case, if instead of usingBaseTranslator._translate_batchfor theGoogleTranslator.translate_batchmethod, we can instead join thebatchlist with linebreaks, run a singletranslatecall on the entire string, and then split the translated string again by linebreaks to return thearrlist of results. This way, we don't need to loop through multiple API calls via thetranslatemethod, rather can get the same set of results with only one API call.I have tried a number of adhoc test cases by choosing random lists of strings and have found that the result is always identical to what you get when running the current method; however, before formalizing tests for this I wanted to submit it and see whether this idea has already been attempted and whether it was found lacking for some reason that I haven't noticed yet. Basically interested in feedback on the idea.