Spaces:
Sleeping
Sleeping
Create utils.py
Browse files
utils.py
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from langdetect import detect
|
| 2 |
+
from deep_translator import GoogleTranslator
|
| 3 |
+
|
| 4 |
+
class Translation:
|
| 5 |
+
def __init__(self, text, destination):
|
| 6 |
+
self.text = text
|
| 7 |
+
self.destination = destination
|
| 8 |
+
try:
|
| 9 |
+
self.original = detect(self.text)
|
| 10 |
+
except Exception as e:
|
| 11 |
+
self.original = "auto"
|
| 12 |
+
def translatef(self):
|
| 13 |
+
translator = GoogleTranslator(source=self.original, target=self.destination)
|
| 14 |
+
translation = translator.translate(self.text)
|
| 15 |
+
return translation
|