Skip to content

Commit

Permalink
Merge pull request #214 from nidhaloff/hotfix/google-max-chars
Browse files Browse the repository at this point in the history
fixed max characters bug
  • Loading branch information
nidhaloff committed May 26, 2023
2 parents 5d13bbd + 458818d commit 356b95c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion deep_translator/google.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def translate(self, text: str, **kwargs) -> str:
@param text: desired text to translate
@return: str: translated text
"""
if is_input_valid(text):
if is_input_valid(text, max_chars=5000):
text = text.strip()
if self._same_source_target() or is_empty(text):
return text
Expand Down
6 changes: 4 additions & 2 deletions deep_translator/validate.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
__copyright__ = "Copyright (C) 2020 Nidhal Baccouri"

from typing import Optional

from deep_translator.exceptions import NotValidLength, NotValidPayload


Expand All @@ -8,7 +10,7 @@ def is_empty(text: str) -> bool:


def is_input_valid(
text: str, min_chars: int = 0, max_chars: int = 5000
text: str, min_chars: int = 0, max_chars: Optional[int] = None
) -> bool:
"""
validate the target text to translate
Expand All @@ -20,7 +22,7 @@ def is_input_valid(

if not isinstance(text, str) or text.isdigit():
raise NotValidPayload(text)
if not min_chars <= len(text) < max_chars:
if max_chars and (not min_chars <= len(text) < max_chars):
raise NotValidLength(text, min_chars, max_chars)

return True

0 comments on commit 356b95c

Please sign in to comment.