=
commited on
Commit
·
198fa9e
1
Parent(s):
f06c14e
fixed imports
Browse files
deep_translator/deep_translator.py
CHANGED
@@ -47,7 +47,7 @@ class GoogleTranslator(ParentTranslator):
|
|
47 |
else:
|
48 |
raise LanguageNotSupportedException(language)
|
49 |
|
50 |
-
def translate(self, payload, payload_tag='q'):
|
51 |
return super().translate(payload, payload_tag)
|
52 |
|
53 |
|
@@ -98,7 +98,7 @@ class PonsTranslator(ParentTranslator):
|
|
98 |
raise LanguageNotSupportedException(lang)
|
99 |
return True
|
100 |
|
101 |
-
def translate(self, payload, payload_tag=None):
|
102 |
from requests.utils import quote
|
103 |
url = "{}{}-{}/{}".format(self.__base_url, self._source, self._target, quote(payload))
|
104 |
response = requests.get(url)
|
|
|
47 |
else:
|
48 |
raise LanguageNotSupportedException(language)
|
49 |
|
50 |
+
def translate(self, payload, payload_tag='q', **kwargs):
|
51 |
return super().translate(payload, payload_tag)
|
52 |
|
53 |
|
|
|
98 |
raise LanguageNotSupportedException(lang)
|
99 |
return True
|
100 |
|
101 |
+
def translate(self, payload, payload_tag=None, **kwargs):
|
102 |
from requests.utils import quote
|
103 |
url = "{}{}-{}/{}".format(self.__base_url, self._source, self._target, quote(payload))
|
104 |
response = requests.get(url)
|
deep_translator/parent.py
CHANGED
@@ -3,9 +3,9 @@
|
|
3 |
|
4 |
from bs4 import BeautifulSoup
|
5 |
import requests
|
6 |
-
from models import BaseTranslator
|
7 |
-
from constants import LANGUAGES_TO_CODES
|
8 |
-
from exceptions import LanguageNotSupportedException, NotValidPayload, ElementNotFoundInGetRequest, NotValidLength
|
9 |
|
10 |
|
11 |
class ParentTranslator(BaseTranslator):
|
@@ -57,7 +57,7 @@ class ParentTranslator(BaseTranslator):
|
|
57 |
raise LanguageNotSupportedException(lang)
|
58 |
return True
|
59 |
|
60 |
-
def translate(self, payload, payload_tag):
|
61 |
"""
|
62 |
main function that uses google translate to translate a text
|
63 |
@param payload: desired text to translate
|
@@ -89,7 +89,7 @@ class ParentTranslator(BaseTranslator):
|
|
89 |
print(e.args)
|
90 |
raise
|
91 |
|
92 |
-
def translate_file(self, path):
|
93 |
try:
|
94 |
with open(path) as f:
|
95 |
text = f.read()
|
@@ -98,7 +98,7 @@ class ParentTranslator(BaseTranslator):
|
|
98 |
except Exception as e:
|
99 |
raise e
|
100 |
|
101 |
-
def translate_sentences(self, sentences=None):
|
102 |
"""
|
103 |
translate many sentences together. This makes sense if you have sentences with different languages
|
104 |
and you want to translate all to unified language. This is handy because it detects
|
|
|
3 |
|
4 |
from bs4 import BeautifulSoup
|
5 |
import requests
|
6 |
+
from .models import BaseTranslator
|
7 |
+
from .constants import LANGUAGES_TO_CODES
|
8 |
+
from .exceptions import LanguageNotSupportedException, NotValidPayload, ElementNotFoundInGetRequest, NotValidLength
|
9 |
|
10 |
|
11 |
class ParentTranslator(BaseTranslator):
|
|
|
57 |
raise LanguageNotSupportedException(lang)
|
58 |
return True
|
59 |
|
60 |
+
def translate(self, payload, payload_tag, **kwargs):
|
61 |
"""
|
62 |
main function that uses google translate to translate a text
|
63 |
@param payload: desired text to translate
|
|
|
89 |
print(e.args)
|
90 |
raise
|
91 |
|
92 |
+
def translate_file(self, path, **kwargs):
|
93 |
try:
|
94 |
with open(path) as f:
|
95 |
text = f.read()
|
|
|
98 |
except Exception as e:
|
99 |
raise e
|
100 |
|
101 |
+
def translate_sentences(self, sentences=None, **kwargs):
|
102 |
"""
|
103 |
translate many sentences together. This makes sense if you have sentences with different languages
|
104 |
and you want to translate all to unified language. This is handy because it detects
|