nidhal baccouri
commited on
Commit
·
804d02e
1
Parent(s):
74f699b
updated translate_file
Browse files
deep_translator/google_trans.py
CHANGED
@@ -124,9 +124,8 @@ class GoogleTranslator(BaseTranslator):
|
|
124 |
"""
|
125 |
try:
|
126 |
with open(path) as f:
|
127 |
-
text = f.read()
|
128 |
-
|
129 |
-
return self.translate(text=text)
|
130 |
except Exception as e:
|
131 |
raise e
|
132 |
|
@@ -164,15 +163,20 @@ class GoogleTranslator(BaseTranslator):
|
|
164 |
if not batch:
|
165 |
raise Exception("Enter your text list that you want to translate")
|
166 |
|
|
|
|
|
167 |
arr = []
|
168 |
-
for text in batch:
|
|
|
169 |
translated = self.translate(text)
|
170 |
arr.append(translated)
|
|
|
171 |
sleep(2)
|
172 |
|
173 |
return arr
|
174 |
|
175 |
|
176 |
# if __name__ == '__main__':
|
177 |
-
#
|
|
|
178 |
# print(text)
|
|
|
124 |
"""
|
125 |
try:
|
126 |
with open(path) as f:
|
127 |
+
text = f.read().strip()
|
128 |
+
return self.translate(text)
|
|
|
129 |
except Exception as e:
|
130 |
raise e
|
131 |
|
|
|
163 |
if not batch:
|
164 |
raise Exception("Enter your text list that you want to translate")
|
165 |
|
166 |
+
print("Please wait.. This may take a couple of seconds because deep_translator sleeps "
|
167 |
+
"for two seconds after each request in order to not spam the google server.")
|
168 |
arr = []
|
169 |
+
for i, text in enumerate(batch):
|
170 |
+
|
171 |
translated = self.translate(text)
|
172 |
arr.append(translated)
|
173 |
+
print("sentence number ", i+1, " has been translated successfully")
|
174 |
sleep(2)
|
175 |
|
176 |
return arr
|
177 |
|
178 |
|
179 |
# if __name__ == '__main__':
|
180 |
+
# batch = ["how are you", "give me that man!", "where are you?"]
|
181 |
+
# text = GoogleTranslator(source="en", target="de").translate_batch(batch)
|
182 |
# print(text)
|
deep_translator/microsoft.py
CHANGED
@@ -130,7 +130,7 @@ class MicrosoftTranslator:
|
|
130 |
"""
|
131 |
try:
|
132 |
with open(path) as f:
|
133 |
-
text = f.read()
|
134 |
return self.translate(text)
|
135 |
except Exception as e:
|
136 |
raise e
|
|
|
130 |
"""
|
131 |
try:
|
132 |
with open(path) as f:
|
133 |
+
text = f.read().strip()
|
134 |
return self.translate(text)
|
135 |
except Exception as e:
|
136 |
raise e
|
deep_translator/mymemory.py
CHANGED
@@ -150,7 +150,7 @@ class MyMemoryTranslator(BaseTranslator):
|
|
150 |
"""
|
151 |
try:
|
152 |
with open(path) as f:
|
153 |
-
text = f.read()
|
154 |
|
155 |
return self.translate(text=text)
|
156 |
except Exception as e:
|
|
|
150 |
"""
|
151 |
try:
|
152 |
with open(path) as f:
|
153 |
+
text = f.read().strip()
|
154 |
|
155 |
return self.translate(text=text)
|
156 |
except Exception as e:
|