nidhal baccouri
commited on
Commit
·
6794418
1
Parent(s):
ee83f7f
fixed google translate bug
Browse files
deep_translator/google_trans.py
CHANGED
|
@@ -38,6 +38,8 @@ class GoogleTranslator(BaseTranslator):
|
|
| 38 |
hl=self._target,
|
| 39 |
sl=self._source)
|
| 40 |
|
|
|
|
|
|
|
| 41 |
@staticmethod
|
| 42 |
def get_supported_languages(as_dict=False):
|
| 43 |
"""
|
|
@@ -100,7 +102,9 @@ class GoogleTranslator(BaseTranslator):
|
|
| 100 |
element = soup.find(self._element_tag, self._element_query)
|
| 101 |
|
| 102 |
if not element:
|
| 103 |
-
|
|
|
|
|
|
|
| 104 |
|
| 105 |
return element.get_text(strip=True)
|
| 106 |
|
|
@@ -162,3 +166,8 @@ class GoogleTranslator(BaseTranslator):
|
|
| 162 |
|
| 163 |
return arr
|
| 164 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
hl=self._target,
|
| 39 |
sl=self._source)
|
| 40 |
|
| 41 |
+
self._alt_element_query = {"class": "result-container"}
|
| 42 |
+
|
| 43 |
@staticmethod
|
| 44 |
def get_supported_languages(as_dict=False):
|
| 45 |
"""
|
|
|
|
| 102 |
element = soup.find(self._element_tag, self._element_query)
|
| 103 |
|
| 104 |
if not element:
|
| 105 |
+
element = soup.find(self._element_tag, self._alt_element_query)
|
| 106 |
+
if not element:
|
| 107 |
+
raise TranslationNotFound(text)
|
| 108 |
|
| 109 |
return element.get_text(strip=True)
|
| 110 |
|
|
|
|
| 166 |
|
| 167 |
return arr
|
| 168 |
|
| 169 |
+
|
| 170 |
+
# if __name__ == '__main__':
|
| 171 |
+
# print(GoogleTranslator.supported_languages)
|
| 172 |
+
# txt = GoogleTranslator(source="en", target="ar").translate("Hello how are you")
|
| 173 |
+
# print("text: ", txt)
|