nidhal baccouri
commited on
Commit
·
0d67af1
1
Parent(s):
0cfe8e5
renamed parent to base
Browse files- deep_translator/__init__.py +1 -1
- deep_translator/__main__.py +0 -1
- deep_translator/{parent.py → base.py} +2 -2
- deep_translator/cli.py +0 -1
- deep_translator/deepl.py +1 -1
- deep_translator/engine.py +2 -8
- deep_translator/google_trans.py +1 -1
- deep_translator/libre.py +1 -1
- deep_translator/linguee.py +1 -1
- deep_translator/microsoft.py +1 -1
- deep_translator/mymemory.py +1 -1
- deep_translator/papago.py +1 -1
- deep_translator/pons.py +2 -2
- deep_translator/qcri.py +1 -1
- deep_translator/yandex.py +1 -1
deep_translator/__init__.py
CHANGED
|
@@ -15,7 +15,7 @@ from .engine import generate_engines_dict, engine
|
|
| 15 |
|
| 16 |
__author__ = """Nidhal Baccouri"""
|
| 17 |
__email__ = 'nidhalbacc@gmail.com'
|
| 18 |
-
__version__ = '1.
|
| 19 |
|
| 20 |
__all__ = [
|
| 21 |
"GoogleTranslator",
|
|
|
|
| 15 |
|
| 16 |
__author__ = """Nidhal Baccouri"""
|
| 17 |
__email__ = 'nidhalbacc@gmail.com'
|
| 18 |
+
__version__ = '1.7.1'
|
| 19 |
|
| 20 |
__all__ = [
|
| 21 |
"GoogleTranslator",
|
deep_translator/__main__.py
CHANGED
|
@@ -1,5 +1,4 @@
|
|
| 1 |
|
| 2 |
-
import argparse
|
| 3 |
from .cli import CLI
|
| 4 |
|
| 5 |
|
|
|
|
| 1 |
|
|
|
|
| 2 |
from .cli import CLI
|
| 3 |
|
| 4 |
|
deep_translator/{parent.py → base.py}
RENAMED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
-
"""
|
| 2 |
|
| 3 |
from .exceptions import NotValidPayload, NotValidLength, InvalidSourceOrTargetLanguage
|
| 4 |
from abc import ABC, abstractmethod
|
|
@@ -7,7 +7,7 @@ import string
|
|
| 7 |
|
| 8 |
class BaseTranslator(ABC):
|
| 9 |
"""
|
| 10 |
-
Abstract class that serve as a
|
| 11 |
"""
|
| 12 |
def __init__(self,
|
| 13 |
base_url=None,
|
|
|
|
| 1 |
+
"""base translator class"""
|
| 2 |
|
| 3 |
from .exceptions import NotValidPayload, NotValidLength, InvalidSourceOrTargetLanguage
|
| 4 |
from abc import ABC, abstractmethod
|
|
|
|
| 7 |
|
| 8 |
class BaseTranslator(ABC):
|
| 9 |
"""
|
| 10 |
+
Abstract class that serve as a base translator for other different translators
|
| 11 |
"""
|
| 12 |
def __init__(self,
|
| 13 |
base_url=None,
|
deep_translator/cli.py
CHANGED
|
@@ -69,7 +69,6 @@ class CLI(object):
|
|
| 69 |
help="all the languages available with the translator"
|
| 70 |
"Run the command deep_translator -trans <translator service> -lang")
|
| 71 |
parsed_args = parser.parse_args(self.custom_args) if self.custom_args else parser.parse_args()
|
| 72 |
-
print(f"parsed args: {parsed_args}")
|
| 73 |
return parsed_args
|
| 74 |
|
| 75 |
def run(self):
|
|
|
|
| 69 |
help="all the languages available with the translator"
|
| 70 |
"Run the command deep_translator -trans <translator service> -lang")
|
| 71 |
parsed_args = parser.parse_args(self.custom_args) if self.custom_args else parser.parse_args()
|
|
|
|
| 72 |
return parsed_args
|
| 73 |
|
| 74 |
def run(self):
|
deep_translator/deepl.py
CHANGED
|
@@ -4,7 +4,7 @@ from .exceptions import (ServerException,
|
|
| 4 |
TranslationNotFound,
|
| 5 |
LanguageNotSupportedException,
|
| 6 |
AuthorizationException)
|
| 7 |
-
from .
|
| 8 |
|
| 9 |
|
| 10 |
class DeepL(object):
|
|
|
|
| 4 |
TranslationNotFound,
|
| 5 |
LanguageNotSupportedException,
|
| 6 |
AuthorizationException)
|
| 7 |
+
from .base import BaseTranslator
|
| 8 |
|
| 9 |
|
| 10 |
class DeepL(object):
|
deep_translator/engine.py
CHANGED
|
@@ -1,16 +1,10 @@
|
|
| 1 |
-
from .
|
| 2 |
-
|
| 3 |
-
# BaseTranslator.register(YandexTranslator)
|
| 4 |
-
# BaseTranslator.register(QCRI)
|
| 5 |
-
# BaseTranslator.register(DeepL)
|
| 6 |
-
# BaseTranslator.register(MicrosoftTranslator)
|
| 7 |
-
# BaseTranslator.register(PapagoTranslator)
|
| 8 |
|
| 9 |
|
| 10 |
def generate_engines_dict(_all: list, _locals: dict) -> dict:
|
| 11 |
base_translator_type = BaseTranslator
|
| 12 |
|
| 13 |
-
def is_translator(__object
|
| 14 |
try:
|
| 15 |
return issubclass(__object, base_translator_type)
|
| 16 |
except TypeError:
|
|
|
|
| 1 |
+
from .base import BaseTranslator
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
|
| 3 |
|
| 4 |
def generate_engines_dict(_all: list, _locals: dict) -> dict:
|
| 5 |
base_translator_type = BaseTranslator
|
| 6 |
|
| 7 |
+
def is_translator(__object) -> bool:
|
| 8 |
try:
|
| 9 |
return issubclass(__object, base_translator_type)
|
| 10 |
except TypeError:
|
deep_translator/google_trans.py
CHANGED
|
@@ -4,7 +4,7 @@ google translator API
|
|
| 4 |
|
| 5 |
from .constants import BASE_URLS, GOOGLE_LANGUAGES_TO_CODES, GOOGLE_LANGUAGES_SECONDARY_NAMES
|
| 6 |
from .exceptions import TooManyRequests, LanguageNotSupportedException, TranslationNotFound, NotValidPayload, RequestError
|
| 7 |
-
from .
|
| 8 |
from bs4 import BeautifulSoup
|
| 9 |
import requests
|
| 10 |
from time import sleep
|
|
|
|
| 4 |
|
| 5 |
from .constants import BASE_URLS, GOOGLE_LANGUAGES_TO_CODES, GOOGLE_LANGUAGES_SECONDARY_NAMES
|
| 6 |
from .exceptions import TooManyRequests, LanguageNotSupportedException, TranslationNotFound, NotValidPayload, RequestError
|
| 7 |
+
from .base import BaseTranslator
|
| 8 |
from bs4 import BeautifulSoup
|
| 9 |
import requests
|
| 10 |
from time import sleep
|
deep_translator/libre.py
CHANGED
|
@@ -3,7 +3,7 @@ LibreTranslate API
|
|
| 3 |
"""
|
| 4 |
|
| 5 |
import requests
|
| 6 |
-
from .
|
| 7 |
from .constants import BASE_URLS,LIBRE_LANGUAGES_TO_CODES, LIBRE_CODES_TO_LANGUAGES
|
| 8 |
from .exceptions import (ServerException,
|
| 9 |
TranslationNotFound,
|
|
|
|
| 3 |
"""
|
| 4 |
|
| 5 |
import requests
|
| 6 |
+
from .base import BaseTranslator
|
| 7 |
from .constants import BASE_URLS,LIBRE_LANGUAGES_TO_CODES, LIBRE_CODES_TO_LANGUAGES
|
| 8 |
from .exceptions import (ServerException,
|
| 9 |
TranslationNotFound,
|
deep_translator/linguee.py
CHANGED
|
@@ -9,7 +9,7 @@ from .exceptions import (LanguageNotSupportedException,
|
|
| 9 |
ElementNotFoundInGetRequest,
|
| 10 |
RequestError,
|
| 11 |
TooManyRequests)
|
| 12 |
-
from .
|
| 13 |
from bs4 import BeautifulSoup
|
| 14 |
import requests
|
| 15 |
from requests.utils import requote_uri
|
|
|
|
| 9 |
ElementNotFoundInGetRequest,
|
| 10 |
RequestError,
|
| 11 |
TooManyRequests)
|
| 12 |
+
from .base import BaseTranslator
|
| 13 |
from bs4 import BeautifulSoup
|
| 14 |
import requests
|
| 15 |
from requests.utils import requote_uri
|
deep_translator/microsoft.py
CHANGED
|
@@ -6,7 +6,7 @@ import sys
|
|
| 6 |
|
| 7 |
from .constants import BASE_URLS, MICROSOFT_CODES_TO_LANGUAGES
|
| 8 |
from .exceptions import LanguageNotSupportedException, ServerException, MicrosoftAPIerror
|
| 9 |
-
from .
|
| 10 |
|
| 11 |
|
| 12 |
class MicrosoftTranslator:
|
|
|
|
| 6 |
|
| 7 |
from .constants import BASE_URLS, MICROSOFT_CODES_TO_LANGUAGES
|
| 8 |
from .exceptions import LanguageNotSupportedException, ServerException, MicrosoftAPIerror
|
| 9 |
+
from .base import BaseTranslator
|
| 10 |
|
| 11 |
|
| 12 |
class MicrosoftTranslator:
|
deep_translator/mymemory.py
CHANGED
|
@@ -10,7 +10,7 @@ from .exceptions import (NotValidPayload,
|
|
| 10 |
LanguageNotSupportedException,
|
| 11 |
RequestError,
|
| 12 |
TooManyRequests)
|
| 13 |
-
from .
|
| 14 |
import requests
|
| 15 |
from time import sleep
|
| 16 |
|
|
|
|
| 10 |
LanguageNotSupportedException,
|
| 11 |
RequestError,
|
| 12 |
TooManyRequests)
|
| 13 |
+
from .base import BaseTranslator
|
| 14 |
import requests
|
| 15 |
from time import sleep
|
| 16 |
|
deep_translator/papago.py
CHANGED
|
@@ -4,7 +4,7 @@ google translator API
|
|
| 4 |
import json
|
| 5 |
from .constants import BASE_URLS, PAPAGO_LANGUAGE_TO_CODE
|
| 6 |
from .exceptions import LanguageNotSupportedException, TranslationNotFound, NotValidPayload
|
| 7 |
-
from .
|
| 8 |
import requests
|
| 9 |
import warnings
|
| 10 |
import logging
|
|
|
|
| 4 |
import json
|
| 5 |
from .constants import BASE_URLS, PAPAGO_LANGUAGE_TO_CODE
|
| 6 |
from .exceptions import LanguageNotSupportedException, TranslationNotFound, NotValidPayload
|
| 7 |
+
from .base import BaseTranslator
|
| 8 |
import requests
|
| 9 |
import warnings
|
| 10 |
import logging
|
deep_translator/pons.py
CHANGED
|
@@ -10,7 +10,7 @@ from .exceptions import (LanguageNotSupportedException,
|
|
| 10 |
ElementNotFoundInGetRequest,
|
| 11 |
RequestError,
|
| 12 |
TooManyRequests)
|
| 13 |
-
from .
|
| 14 |
from requests.utils import requote_uri
|
| 15 |
|
| 16 |
|
|
@@ -104,7 +104,7 @@ class PonsTranslator(BaseTranslator):
|
|
| 104 |
for el in elements:
|
| 105 |
temp = ''
|
| 106 |
for e in el.findAll('a'):
|
| 107 |
-
if e.
|
| 108 |
if e and "/translate/{}-{}/".format(self._target, self._source) in e.get('href'):
|
| 109 |
temp += e.get_text() + ' '
|
| 110 |
filtered_elements.append(temp)
|
|
|
|
| 10 |
ElementNotFoundInGetRequest,
|
| 11 |
RequestError,
|
| 12 |
TooManyRequests)
|
| 13 |
+
from .base import BaseTranslator
|
| 14 |
from requests.utils import requote_uri
|
| 15 |
|
| 16 |
|
|
|
|
| 104 |
for el in elements:
|
| 105 |
temp = ''
|
| 106 |
for e in el.findAll('a'):
|
| 107 |
+
if e.base.name == 'div':
|
| 108 |
if e and "/translate/{}-{}/".format(self._target, self._source) in e.get('href'):
|
| 109 |
temp += e.get_text() + ' '
|
| 110 |
filtered_elements.append(temp)
|
deep_translator/qcri.py
CHANGED
|
@@ -2,7 +2,7 @@
|
|
| 2 |
import requests
|
| 3 |
from .constants import BASE_URLS, QCRI_LANGUAGE_TO_CODE
|
| 4 |
from .exceptions import (ServerException, TranslationNotFound)
|
| 5 |
-
from .
|
| 6 |
|
| 7 |
|
| 8 |
class QCRI(object):
|
|
|
|
| 2 |
import requests
|
| 3 |
from .constants import BASE_URLS, QCRI_LANGUAGE_TO_CODE
|
| 4 |
from .exceptions import (ServerException, TranslationNotFound)
|
| 5 |
+
from .base import BaseTranslator
|
| 6 |
|
| 7 |
|
| 8 |
class QCRI(object):
|
deep_translator/yandex.py
CHANGED
|
@@ -5,7 +5,7 @@ import requests
|
|
| 5 |
from .constants import BASE_URLS
|
| 6 |
from .exceptions import (RequestError, ServerException,
|
| 7 |
TranslationNotFound, TooManyRequests)
|
| 8 |
-
from .
|
| 9 |
|
| 10 |
|
| 11 |
class YandexTranslator(object):
|
|
|
|
| 5 |
from .constants import BASE_URLS
|
| 6 |
from .exceptions import (RequestError, ServerException,
|
| 7 |
TranslationNotFound, TooManyRequests)
|
| 8 |
+
from .base import BaseTranslator
|
| 9 |
|
| 10 |
|
| 11 |
class YandexTranslator(object):
|