Nidhal Baccouri
commited on
Commit
·
9b91505
1
Parent(s):
73894d1
fixed mymemory return_all
Browse files
deep_translator/__init__.py
CHANGED
|
@@ -14,7 +14,7 @@ from deep_translator.yandex import YandexTranslator
|
|
| 14 |
|
| 15 |
__author__ = """Nidhal Baccouri"""
|
| 16 |
__email__ = "nidhalbacc@gmail.com"
|
| 17 |
-
__version__ = "1.
|
| 18 |
|
| 19 |
__all__ = [
|
| 20 |
"GoogleTranslator",
|
|
|
|
| 14 |
|
| 15 |
__author__ = """Nidhal Baccouri"""
|
| 16 |
__email__ = "nidhalbacc@gmail.com"
|
| 17 |
+
__version__ = "1.9.0"
|
| 18 |
|
| 19 |
__all__ = [
|
| 20 |
"GoogleTranslator",
|
deep_translator/mymemory.py
CHANGED
|
@@ -76,11 +76,17 @@ class MyMemoryTranslator(BaseTranslator):
|
|
| 76 |
|
| 77 |
response.close()
|
| 78 |
translation = data.get("responseData").get("translatedText")
|
|
|
|
|
|
|
| 79 |
if translation:
|
| 80 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 81 |
|
| 82 |
elif not translation:
|
| 83 |
-
all_matches = data.get("matches")
|
| 84 |
matches = (match["translation"] for match in all_matches)
|
| 85 |
next_match = next(matches)
|
| 86 |
return next_match if not return_all else list(all_matches)
|
|
|
|
| 76 |
|
| 77 |
response.close()
|
| 78 |
translation = data.get("responseData").get("translatedText")
|
| 79 |
+
all_matches = data.get("matches", [])
|
| 80 |
+
|
| 81 |
if translation:
|
| 82 |
+
if not return_all:
|
| 83 |
+
return translation
|
| 84 |
+
else:
|
| 85 |
+
# append translation at the start of the matches list
|
| 86 |
+
return [translation] + list(all_matches)
|
| 87 |
+
|
| 88 |
|
| 89 |
elif not translation:
|
|
|
|
| 90 |
matches = (match["translation"] for match in all_matches)
|
| 91 |
next_match = next(matches)
|
| 92 |
return next_match if not return_all else list(all_matches)
|