How to solve text must be a valid text with maximum 5000 character, otherwise it cannot be translated
Asked Answered
J

1

0

I am using google translate api to translate some text.

The package is from deep_translator import GoogleTranslator.

However, every time it would return the error: --> text must be a valid text with maximum 5000 character, otherwise it cannot be translated

Does anyone know how to solve this? Is it possible to have a paid version of api to expand the maximum characters?

Thanks a lot!

Jalopy answered 11/1, 2022 at 20:38 Comment(2)
Can you split the text into chunks and submit each chunk (eg. splitting at the closest paragraph with less than 5000 characters)?Maynardmayne
The 5,000 character limit is per request. If you look at the Quotas page there is a 6,000,000 character per minute quota. So my suggestion is to break your text into chunks and make requests that way.Solidary
A
2

You could split the text up in chunks in either words or sentences.

Using the NLTK module:

pip install nltk
import nltk
#nltk.download('popular') -- only need to do this once
x = '''I am using google translate api to translate some text.

The package is from deep_translator import GoogleTranslator.

However, every time it would return the error: --> text must be a valid text with maximum 5000 character, otherwise it cannot be translated

Does anyone know how to solve this? Is it possible to have a paid version of api to expand the maximum characters?

Thanks a lot!'''

x = nltk.tokenize.sent_tokenize(x)
for sentence in x:
    print(sentence) #send each sentence to translator
Aquacade answered 11/1, 2022 at 20:53 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.