Merge pull request #214 from nidhaloff/hotfix/google-max-chars
Browse files- deep_translator/google.py +1 -1
- deep_translator/validate.py +4 -2
deep_translator/google.py
CHANGED
|
@@ -54,7 +54,7 @@ class GoogleTranslator(BaseTranslator):
|
|
| 54 |
@param text: desired text to translate
|
| 55 |
@return: str: translated text
|
| 56 |
"""
|
| 57 |
-
if is_input_valid(text):
|
| 58 |
text = text.strip()
|
| 59 |
if self._same_source_target() or is_empty(text):
|
| 60 |
return text
|
|
|
|
| 54 |
@param text: desired text to translate
|
| 55 |
@return: str: translated text
|
| 56 |
"""
|
| 57 |
+
if is_input_valid(text, max_chars=5000):
|
| 58 |
text = text.strip()
|
| 59 |
if self._same_source_target() or is_empty(text):
|
| 60 |
return text
|
deep_translator/validate.py
CHANGED
|
@@ -1,5 +1,7 @@
|
|
| 1 |
__copyright__ = "Copyright (C) 2020 Nidhal Baccouri"
|
| 2 |
|
|
|
|
|
|
|
| 3 |
from deep_translator.exceptions import NotValidLength, NotValidPayload
|
| 4 |
|
| 5 |
|
|
@@ -8,7 +10,7 @@ def is_empty(text: str) -> bool:
|
|
| 8 |
|
| 9 |
|
| 10 |
def is_input_valid(
|
| 11 |
-
text: str, min_chars: int = 0, max_chars: int =
|
| 12 |
) -> bool:
|
| 13 |
"""
|
| 14 |
validate the target text to translate
|
|
@@ -20,7 +22,7 @@ def is_input_valid(
|
|
| 20 |
|
| 21 |
if not isinstance(text, str) or text.isdigit():
|
| 22 |
raise NotValidPayload(text)
|
| 23 |
-
if not min_chars <= len(text) < max_chars:
|
| 24 |
raise NotValidLength(text, min_chars, max_chars)
|
| 25 |
|
| 26 |
return True
|
|
|
|
| 1 |
__copyright__ = "Copyright (C) 2020 Nidhal Baccouri"
|
| 2 |
|
| 3 |
+
from typing import Optional
|
| 4 |
+
|
| 5 |
from deep_translator.exceptions import NotValidLength, NotValidPayload
|
| 6 |
|
| 7 |
|
|
|
|
| 10 |
|
| 11 |
|
| 12 |
def is_input_valid(
|
| 13 |
+
text: str, min_chars: int = 0, max_chars: Optional[int] = None
|
| 14 |
) -> bool:
|
| 15 |
"""
|
| 16 |
validate the target text to translate
|
|
|
|
| 22 |
|
| 23 |
if not isinstance(text, str) or text.isdigit():
|
| 24 |
raise NotValidPayload(text)
|
| 25 |
+
if max_chars and (not min_chars <= len(text) < max_chars):
|
| 26 |
raise NotValidLength(text, min_chars, max_chars)
|
| 27 |
|
| 28 |
return True
|