=
commited on
Commit
·
a3c0252
1
Parent(s):
a545c52
start working on pons issue
Browse files- deep_translator/exceptions.py +3 -3
- deep_translator/google_trans.py +2 -2
- deep_translator/linguee.py +2 -2
- deep_translator/mymemory.py +2 -2
- deep_translator/pons.py +2 -2
- examples/pons.py +4 -1
deep_translator/exceptions.py
CHANGED
@@ -21,11 +21,11 @@ class NotValidPayload(BaseError):
|
|
21 |
super(NotValidPayload, self).__init__(val, message)
|
22 |
|
23 |
|
24 |
-
class
|
25 |
def __init__(self,
|
26 |
val,
|
27 |
-
message='
|
28 |
-
super(
|
29 |
|
30 |
|
31 |
class NotValidLength(BaseError):
|
|
|
21 |
super(NotValidPayload, self).__init__(val, message)
|
22 |
|
23 |
|
24 |
+
class TranslationNotFound(BaseError):
|
25 |
def __init__(self,
|
26 |
val,
|
27 |
+
message='No translation was found using the current translator. Try another translator?'):
|
28 |
+
super(TranslationNotFound, self).__init__(val, message)
|
29 |
|
30 |
|
31 |
class NotValidLength(BaseError):
|
deep_translator/google_trans.py
CHANGED
@@ -1,6 +1,6 @@
|
|
1 |
|
2 |
from deep_translator.constants import BASE_URLS, GOOGLE_LANGUAGES_TO_CODES
|
3 |
-
from deep_translator.exceptions import LanguageNotSupportedException,
|
4 |
from deep_translator.parent import BaseTranslator
|
5 |
from bs4 import BeautifulSoup
|
6 |
import requests
|
@@ -76,7 +76,7 @@ class GoogleTranslator(BaseTranslator):
|
|
76 |
soup = BeautifulSoup(response.text, 'html.parser')
|
77 |
element = soup.find(self._element_tag, self._element_query)
|
78 |
if not element:
|
79 |
-
raise
|
80 |
|
81 |
return element.get_text(strip=True)
|
82 |
|
|
|
1 |
|
2 |
from deep_translator.constants import BASE_URLS, GOOGLE_LANGUAGES_TO_CODES
|
3 |
+
from deep_translator.exceptions import LanguageNotSupportedException, TranslationNotFound, NotValidPayload
|
4 |
from deep_translator.parent import BaseTranslator
|
5 |
from bs4 import BeautifulSoup
|
6 |
import requests
|
|
|
76 |
soup = BeautifulSoup(response.text, 'html.parser')
|
77 |
element = soup.find(self._element_tag, self._element_query)
|
78 |
if not element:
|
79 |
+
raise TranslationNotFound(element)
|
80 |
|
81 |
return element.get_text(strip=True)
|
82 |
|
deep_translator/linguee.py
CHANGED
@@ -1,5 +1,5 @@
|
|
1 |
from deep_translator.constants import BASE_URLS, LINGUEE_LANGUAGES_TO_CODES, LINGUEE_CODE_TO_LANGUAGE
|
2 |
-
from deep_translator.exceptions import LanguageNotSupportedException,
|
3 |
from deep_translator.parent import BaseTranslator
|
4 |
from bs4 import BeautifulSoup
|
5 |
import requests
|
@@ -62,7 +62,7 @@ class LingueeTranslator(BaseTranslator):
|
|
62 |
soup = BeautifulSoup(response.text, 'html.parser')
|
63 |
elements = soup.find_all(self._element_tag, self._element_query)
|
64 |
if not elements:
|
65 |
-
raise
|
66 |
|
67 |
if 'return_all' in kwargs and kwargs.get('return_all'):
|
68 |
return [el.get_text(strip=True) for el in elements]
|
|
|
1 |
from deep_translator.constants import BASE_URLS, LINGUEE_LANGUAGES_TO_CODES, LINGUEE_CODE_TO_LANGUAGE
|
2 |
+
from deep_translator.exceptions import LanguageNotSupportedException, TranslationNotFound, NotValidPayload, NotValidLength
|
3 |
from deep_translator.parent import BaseTranslator
|
4 |
from bs4 import BeautifulSoup
|
5 |
import requests
|
|
|
62 |
soup = BeautifulSoup(response.text, 'html.parser')
|
63 |
elements = soup.find_all(self._element_tag, self._element_query)
|
64 |
if not elements:
|
65 |
+
raise TranslationNotFound(elements)
|
66 |
|
67 |
if 'return_all' in kwargs and kwargs.get('return_all'):
|
68 |
return [el.get_text(strip=True) for el in elements]
|
deep_translator/mymemory.py
CHANGED
@@ -1,6 +1,6 @@
|
|
1 |
|
2 |
from deep_translator.constants import BASE_URLS, GOOGLE_LANGUAGES_TO_CODES
|
3 |
-
from deep_translator.exceptions import NotValidPayload
|
4 |
from deep_translator.parent import BaseTranslator
|
5 |
import requests
|
6 |
|
@@ -52,7 +52,7 @@ class MyMemoryTranslator(BaseTranslator):
|
|
52 |
headers=self.headers)
|
53 |
data = response.json()
|
54 |
if not data:
|
55 |
-
|
56 |
|
57 |
translation = data.get('responseData').get('translatedText')
|
58 |
if translation:
|
|
|
1 |
|
2 |
from deep_translator.constants import BASE_URLS, GOOGLE_LANGUAGES_TO_CODES
|
3 |
+
from deep_translator.exceptions import NotValidPayload, TranslationNotFound
|
4 |
from deep_translator.parent import BaseTranslator
|
5 |
import requests
|
6 |
|
|
|
52 |
headers=self.headers)
|
53 |
data = response.json()
|
54 |
if not data:
|
55 |
+
TranslationNotFound(text)
|
56 |
|
57 |
translation = data.get('responseData').get('translatedText')
|
58 |
if translation:
|
deep_translator/pons.py
CHANGED
@@ -2,7 +2,7 @@
|
|
2 |
from bs4 import BeautifulSoup
|
3 |
import requests
|
4 |
from deep_translator.constants import BASE_URLS, PONS_LANGUAGES_TO_CODES, PONS_CODES_TO_LANGUAGES
|
5 |
-
from deep_translator.exceptions import LanguageNotSupportedException,
|
6 |
from deep_translator.parent import BaseTranslator
|
7 |
from requests.utils import requote_uri
|
8 |
|
@@ -66,7 +66,7 @@ class PonsTranslator(BaseTranslator):
|
|
66 |
soup = BeautifulSoup(response.text, 'html.parser')
|
67 |
elements = soup.findAll(self._element_tag, self._element_query)
|
68 |
if not elements:
|
69 |
-
raise
|
70 |
|
71 |
eof = []
|
72 |
for el in elements:
|
|
|
2 |
from bs4 import BeautifulSoup
|
3 |
import requests
|
4 |
from deep_translator.constants import BASE_URLS, PONS_LANGUAGES_TO_CODES, PONS_CODES_TO_LANGUAGES
|
5 |
+
from deep_translator.exceptions import LanguageNotSupportedException, TranslationNotFound, NotValidPayload
|
6 |
from deep_translator.parent import BaseTranslator
|
7 |
from requests.utils import requote_uri
|
8 |
|
|
|
66 |
soup = BeautifulSoup(response.text, 'html.parser')
|
67 |
elements = soup.findAll(self._element_tag, self._element_query)
|
68 |
if not elements:
|
69 |
+
raise TranslationNotFound(word)
|
70 |
|
71 |
eof = []
|
72 |
for el in elements:
|
examples/pons.py
CHANGED
@@ -4,4 +4,7 @@ from deep_translator import PonsTranslator
|
|
4 |
|
5 |
res = PonsTranslator(source='de', target='en').translate('übersetzen', return_all=False)
|
6 |
|
7 |
-
|
|
|
|
|
|
|
|
4 |
|
5 |
res = PonsTranslator(source='de', target='en').translate('übersetzen', return_all=False)
|
6 |
|
7 |
+
|
8 |
+
e2a = PonsTranslator('ar', 'en').translate('آخُذ اَلْباص.')
|
9 |
+
|
10 |
+
print(e2a)
|