Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove deprecated methods in translate #35

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 7 additions & 12 deletions textaugment/translate.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

from .constants import LANGUAGES
from textblob import TextBlob
from textblob.translate import NotTranslated
from googletrans import Translator


Expand Down Expand Up @@ -132,16 +131,12 @@ def augment(self, data):
if type(data) is not str:
raise TypeError("DataType must be a string")
data = TextBlob(data.lower())
try:
data = data.translate(from_lang=self.src, to=self.to)
data = data.translate(from_lang=self.to, to=self.src)
except NotTranslated:
try: # Switch to googletrans to do translation.
translator = Translator()
data = translator.translate(data, dest=self.to, src=self.src).text
data = translator.translate(data, dest=self.src, src=self.to).text
except Exception:
print("Error Not translated.\n")
raise
try: # Switch to googletrans to do translation.
translator = Translator()
data = translator.translate(data, dest=self.to, src=self.src).text
data = translator.translate(data, dest=self.src, src=self.to).text
except Exception:
print("Error Not translated.\n")
raise

return str(data).lower()