chat-with-em / utils.py
as-cle-bert's picture
Create utils.py
10115f1 verified
raw
history blame contribute delete
No virus
518 Bytes
from langdetect import detect
from deep_translator import GoogleTranslator
class Translation:
def __init__(self, text, destination):
self.text = text
self.destination = destination
try:
self.original = detect(self.text)
except Exception as e:
self.original = "auto"
def translatef(self):
translator = GoogleTranslator(source=self.original, target=self.destination)
translation = translator.translate(self.text)
return translation