nidhaloff / deep-translator

A flexible free and unlimited python tool to translate between different languages in a simple way using multiple translators.
https://deep-translator.readthedocs.io/en/latest/?badge=latest
Apache License 2.0
1.61k stars 186 forks source link

NotValidPayload does not return relevant data #200

Closed travisrecupero closed 1 year ago

travisrecupero commented 1 year ago

Description

I created an xml translator that uses this api for translations. I used to translate one word at a time until I saw translate_batch(..). I am currently using the GoogleTranslator class (I don't reinstantiate this). The problem is that when one string of a batch is invalid, the string is not printed in the error. On my end, I cant step into translate_batch to find my invalid string.

Note that I am handling the 5k character limit so this is not the issue (by the error message, one might think this is their problem instead of a invalid translation).

What I Did

python main.py

I just added an except and a print when I get NotValidPayload

travisrecupero commented 1 year ago

Update: I found the error in my application. When using this API, strings that include a digit are accepted as valid payloads but strings that are only a digit or digits (text.isdigit()) are invalid.

I can update the code in validate.py to handle this case. I can also update the code in exceptions.py to give the user explicit string errors when using translate_batch(..). Let me know if you would like me open a PR.

jiaulislam commented 1 year ago

@travisrecupero I have seen that issue in my earlier project. I didn't know the reason or understood why it should raise an exception if its only digit but I guess you open a PR for that issue, as I was working some other areas of this project it would be appreciated.

nidhaloff commented 1 year ago

@travisrecupero Sure please open a PR and I will get to it asap