Skip to content

Commit

Permalink
Updated google translate
Browse files Browse the repository at this point in the history
  • Loading branch information
anatolykopyl committed Apr 2, 2021
1 parent 7f3d672 commit 30ed7ff
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
2 changes: 2 additions & 0 deletions lib/detection.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ def blacklisted(self, blacklists, group_name, text, detec_state):
def tradWrapper(self, detect_func, group, words, text, detec_state):
for lang, trads in words.items():
for trad in trads:
if isinstance(trad, list):
trad = trad[0]
detec_state = detect_func(group=group, word=trad, lang=lang, text=text, detec_state=detec_state)
return detec_state

Expand Down
8 changes: 4 additions & 4 deletions lib/translate.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
from googletrans import Translator
from google_trans_new import google_translator
from pprint import pprint

def translate_keywords(keywords_langs, words_to_translate):
words = {word: {lang: [] for lang in keywords_langs} for word in words_to_translate}
translator = Translator()
translator = google_translator()
for word in words.keys():
for code in words[word].keys():
translation = translator.translate(word, dest=code)
words[word][code].append(translation.text)
translation = translator.translate(word, lang_tgt=code)
words[word][code].append(translation)

#pprint(words) # If you want to debug the translated words, uncomment it

Expand Down

0 comments on commit 30ed7ff

Please sign in to comment.