Chris commited on
Commit
5cbd28e
·
1 Parent(s): fdb2846

pre-final refactor commit. Builds clean. Minor grammar and syntax fixes remaining.

Browse files
deep_translator/__init__.py CHANGED
@@ -1,16 +1,17 @@
1
  """Top-level package for Deep Translator"""
2
 
3
- from google_trans import GoogleTranslator
4
- from pons import PonsTranslator
5
- from linguee import LingueeTranslator
6
- from mymemory import MyMemoryTranslator
7
- from yandex import YandexTranslator
8
- from qcri import QCRI
9
- from deepl import DeepL
10
- from detection import single_detection, batch_detection
11
- from microsoft import MicrosoftTranslator
 
12
 
13
- # These should be declared in setup.cfg, setting them here is redundant
14
  # __author__ = """Nidhal Baccouri"""
15
  # __email__ = '[email protected]'
16
  # __version__ = '1.4.4'
 
1
  """Top-level package for Deep Translator"""
2
 
3
+ # TODO: Discussion: Do these need to be in __init__.py? Are they intended to be exportable?
4
+ from .google_trans import GoogleTranslator
5
+ from .pons import PonsTranslator
6
+ from .linguee import LingueeTranslator
7
+ from .mymemory import MyMemoryTranslator
8
+ from .yandex import YandexTranslator
9
+ from .qcri import QCRI
10
+ from .deepl import DeepL
11
+ from .detection import single_detection, batch_detection
12
+ from .microsoft import MicrosoftTranslator
13
 
14
+ # TODO: Discussion: These should be declared in setup.cfg, setting them here is redundant
15
  # __author__ = """Nidhal Baccouri"""
16
  # __email__ = '[email protected]'
17
  # __version__ = '1.4.4'
deep_translator/__main__.py CHANGED
@@ -1,15 +1,15 @@
1
  """Console script for deep_translator."""
2
 
3
  import click
4
- from google_trans import GoogleTranslator
5
- from mymemory import MyMemoryTranslator
6
- from deepl import DeepL
7
- from qcri import QCRI
8
- from linguee import LingueeTranslator
9
- from pons import PonsTranslator
10
- from yandex import YandexTranslator
11
- from microsoft import MicrosoftTranslator
12
- from papago import PapagoTranslator
13
 
14
  CONTEXT_SETTINGS = dict(help_option_names=["-h", "--help"])
15
 
@@ -41,18 +41,16 @@ CONTEXT_SETTINGS = dict(help_option_names=["-h", "--help"])
41
  @click.option(
42
  "--api-key",
43
  type=str,
44
- help="required for DeepL, QCRI, Yandex, Microsoft and Papago translators"
45
- )
46
  @click.option(
47
  "--languages",
48
  "-lang",
49
  is_flag=True,
50
  help="list all the languages available with the translator."
51
- " Run with deep_translator <translator service> -lang",
52
- )
53
- def deep_translator(translator, source, target, text, api_key, languages):
54
  """
55
- Use TRANSLATOR to translate source material into another language.\n
56
  Available translators include: Google, MyMemory, QCRI, Linguee, Pons, Yandex, Microsoft (Bing), and Papago.\n
57
  \f
58
  function responsible for parsing terminal arguments and provide them for
@@ -156,4 +154,4 @@ def print_supported_languages(requested_translator, api_key):
156
  click.echo(f"|- {k}: {v}")
157
 
158
  if __name__ == "__main__":
159
- deep_translator()
 
1
  """Console script for deep_translator."""
2
 
3
  import click
4
+ from .google_trans import GoogleTranslator
5
+ from .mymemory import MyMemoryTranslator
6
+ from .deepl import DeepL
7
+ from .qcri import QCRI
8
+ from .linguee import LingueeTranslator
9
+ from .pons import PonsTranslator
10
+ from .yandex import YandexTranslator
11
+ from .microsoft import MicrosoftTranslator
12
+ from .papago import PapagoTranslator
13
 
14
  CONTEXT_SETTINGS = dict(help_option_names=["-h", "--help"])
15
 
 
41
  @click.option(
42
  "--api-key",
43
  type=str,
44
+ help="required for DeepL, QCRI, Yandex, Microsoft and Papago translators")
 
45
  @click.option(
46
  "--languages",
47
  "-lang",
48
  is_flag=True,
49
  help="list all the languages available with the translator."
50
+ " Run with deep_translator <translator service> -lang",)
51
+ def main(translator, source, target, text, api_key, languages):
 
52
  """
53
+ Use TRANSLATOR to translate source material into another language.
54
  Available translators include: Google, MyMemory, QCRI, Linguee, Pons, Yandex, Microsoft (Bing), and Papago.\n
55
  \f
56
  function responsible for parsing terminal arguments and provide them for
 
154
  click.echo(f"|- {k}: {v}")
155
 
156
  if __name__ == "__main__":
157
+ main()
deep_translator/deepl.py CHANGED
@@ -1,6 +1,6 @@
1
  import requests
2
- from constants import BASE_URLS, DEEPL_LANGUAGE_TO_CODE
3
- from exceptions import (ServerException,
4
  TranslationNotFound,
5
  LanguageNotSupportedException,
6
  AuthorizationException)
 
1
  import requests
2
+ from .constants import BASE_URLS, DEEPL_LANGUAGE_TO_CODE
3
+ from .exceptions import (ServerException,
4
  TranslationNotFound,
5
  LanguageNotSupportedException,
6
  AuthorizationException)
deep_translator/detection.py CHANGED
@@ -2,7 +2,7 @@
2
  language detection API
3
  """
4
  import requests
5
- from configs import config
6
  from requests.exceptions import HTTPError
7
 
8
 
 
2
  language detection API
3
  """
4
  import requests
5
+ from .configs import config # TODO: Discussion: Could this be moved here and remove configs.py entirely?
6
  from requests.exceptions import HTTPError
7
 
8
 
deep_translator/google_trans.py CHANGED
@@ -2,9 +2,9 @@
2
  google translator API
3
  """
4
 
5
- from constants import BASE_URLS, GOOGLE_LANGUAGES_TO_CODES
6
- from exceptions import TooManyRequests, LanguageNotSupportedException, TranslationNotFound, NotValidPayload, RequestError
7
- from parent import BaseTranslator
8
  from bs4 import BeautifulSoup
9
  import requests
10
  from time import sleep
 
2
  google translator API
3
  """
4
 
5
+ from .constants import BASE_URLS, GOOGLE_LANGUAGES_TO_CODES
6
+ from .exceptions import TooManyRequests, LanguageNotSupportedException, TranslationNotFound, NotValidPayload, RequestError
7
+ from .parent import BaseTranslator
8
  from bs4 import BeautifulSoup
9
  import requests
10
  from time import sleep
deep_translator/linguee.py CHANGED
@@ -2,14 +2,14 @@
2
  linguee translator API
3
  """
4
 
5
- from constants import BASE_URLS, LINGUEE_LANGUAGES_TO_CODES, LINGUEE_CODE_TO_LANGUAGE
6
- from exceptions import (LanguageNotSupportedException,
7
  TranslationNotFound,
8
  NotValidPayload,
9
  ElementNotFoundInGetRequest,
10
  RequestError,
11
  TooManyRequests)
12
- from parent import BaseTranslator
13
  from bs4 import BeautifulSoup
14
  import requests
15
  from requests.utils import requote_uri
 
2
  linguee translator API
3
  """
4
 
5
+ from .constants import BASE_URLS, LINGUEE_LANGUAGES_TO_CODES, LINGUEE_CODE_TO_LANGUAGE
6
+ from .exceptions import (LanguageNotSupportedException,
7
  TranslationNotFound,
8
  NotValidPayload,
9
  ElementNotFoundInGetRequest,
10
  RequestError,
11
  TooManyRequests)
12
+ from .parent import BaseTranslator
13
  from bs4 import BeautifulSoup
14
  import requests
15
  from requests.utils import requote_uri
deep_translator/microsoft.py CHANGED
@@ -4,8 +4,8 @@ import requests
4
  import logging
5
  import sys
6
 
7
- from constants import BASE_URLS, MICROSOFT_CODES_TO_LANGUAGES
8
- from exceptions import LanguageNotSupportedException, ServerException, MicrosoftAPIerror
9
 
10
 
11
  class MicrosoftTranslator:
 
4
  import logging
5
  import sys
6
 
7
+ from .constants import BASE_URLS, MICROSOFT_CODES_TO_LANGUAGES
8
+ from .exceptions import LanguageNotSupportedException, ServerException, MicrosoftAPIerror
9
 
10
 
11
  class MicrosoftTranslator:
deep_translator/mymemory.py CHANGED
@@ -4,13 +4,13 @@ mymemory translator API
4
  import logging
5
  import warnings
6
 
7
- from constants import BASE_URLS, GOOGLE_LANGUAGES_TO_CODES
8
- from exceptions import (NotValidPayload,
9
  TranslationNotFound,
10
  LanguageNotSupportedException,
11
  RequestError,
12
  TooManyRequests)
13
- from parent import BaseTranslator
14
  import requests
15
  from time import sleep
16
 
 
4
  import logging
5
  import warnings
6
 
7
+ from .constants import BASE_URLS, GOOGLE_LANGUAGES_TO_CODES
8
+ from .exceptions import (NotValidPayload,
9
  TranslationNotFound,
10
  LanguageNotSupportedException,
11
  RequestError,
12
  TooManyRequests)
13
+ from .parent import BaseTranslator
14
  import requests
15
  from time import sleep
16
 
deep_translator/papago.py CHANGED
@@ -2,8 +2,8 @@
2
  google translator API
3
  """
4
  import json
5
- from constants import BASE_URLS, PAPAGO_LANGUAGE_TO_CODE
6
- from exceptions import LanguageNotSupportedException, TranslationNotFound, NotValidPayload
7
  import requests
8
  import warnings
9
  import logging
 
2
  google translator API
3
  """
4
  import json
5
+ from .constants import BASE_URLS, PAPAGO_LANGUAGE_TO_CODE
6
+ from .exceptions import LanguageNotSupportedException, TranslationNotFound, NotValidPayload
7
  import requests
8
  import warnings
9
  import logging
deep_translator/parent.py CHANGED
@@ -1,6 +1,6 @@
1
  """parent translator class"""
2
 
3
- from exceptions import NotValidPayload, NotValidLength, InvalidSourceOrTargetLanguage
4
  from abc import ABC, abstractmethod
5
  import string
6
  class BaseTranslator(ABC):
 
1
  """parent translator class"""
2
 
3
+ from .exceptions import NotValidPayload, NotValidLength, InvalidSourceOrTargetLanguage
4
  from abc import ABC, abstractmethod
5
  import string
6
  class BaseTranslator(ABC):
deep_translator/pons.py CHANGED
@@ -3,14 +3,14 @@ pons translator API
3
  """
4
  from bs4 import BeautifulSoup
5
  import requests
6
- from constants import BASE_URLS, PONS_LANGUAGES_TO_CODES, PONS_CODES_TO_LANGUAGES
7
- from exceptions import (LanguageNotSupportedException,
8
  TranslationNotFound,
9
  NotValidPayload,
10
  ElementNotFoundInGetRequest,
11
  RequestError,
12
  TooManyRequests)
13
- from parent import BaseTranslator
14
  from requests.utils import requote_uri
15
 
16
 
 
3
  """
4
  from bs4 import BeautifulSoup
5
  import requests
6
+ from .constants import BASE_URLS, PONS_LANGUAGES_TO_CODES, PONS_CODES_TO_LANGUAGES
7
+ from .exceptions import (LanguageNotSupportedException,
8
  TranslationNotFound,
9
  NotValidPayload,
10
  ElementNotFoundInGetRequest,
11
  RequestError,
12
  TooManyRequests)
13
+ from .parent import BaseTranslator
14
  from requests.utils import requote_uri
15
 
16
 
deep_translator/qcri.py CHANGED
@@ -1,7 +1,7 @@
1
 
2
  import requests
3
- from constants import BASE_URLS, QCRI_LANGUAGE_TO_CODE
4
- from exceptions import (ServerException, TranslationNotFound)
5
 
6
  class QCRI(object):
7
  """
 
1
 
2
  import requests
3
+ from .constants import BASE_URLS, QCRI_LANGUAGE_TO_CODE
4
+ from .exceptions import (ServerException, TranslationNotFound)
5
 
6
  class QCRI(object):
7
  """
deep_translator/tests/test_cli.py CHANGED
@@ -1,9 +1,9 @@
1
  #!/usr/bin/env python
2
 
3
- """Tests for `deep_translator` package."""
4
 
5
  from click.testing import CliRunner
6
- from deep_translator.cli import main
7
 
8
  def results_test():
9
  runner = CliRunner()
 
1
  #!/usr/bin/env python
2
 
3
+ """Tests for the CLI interface."""
4
 
5
  from click.testing import CliRunner
6
+ from deep_translator import cli
7
 
8
  def results_test():
9
  runner = CliRunner()
deep_translator/utils.py CHANGED
@@ -1,3 +1,4 @@
1
  """
2
  utilities
3
  """
 
 
1
  """
2
  utilities
3
  """
4
+ # TODO: Discussion: Whats the purpsoe of this module?
deep_translator/yandex.py CHANGED
@@ -2,8 +2,8 @@
2
  Yandex translator API
3
  """
4
  import requests
5
- from constants import BASE_URLS
6
- from exceptions import (RequestError, ServerException, TranslationNotFound, TooManyRequests)
7
 
8
  class YandexTranslator(object):
9
  """
 
2
  Yandex translator API
3
  """
4
  import requests
5
+ from .constants import BASE_URLS
6
+ from .exceptions import (RequestError, ServerException, TranslationNotFound, TooManyRequests)
7
 
8
  class YandexTranslator(object):
9
  """
setup.cfg CHANGED
@@ -35,22 +35,22 @@ keywords = deep_translator, deepL, DeepL, translator, translation, automation,
35
  YANDEX, MyMemory translator, Linguee, QCRI, Language, Language detection,
36
  detect language, free translation, unlimited translation, translate for free
37
 
38
- [options]
39
- zip_safe = 0
40
- setup_requires = pytest-runner
41
- install_requires = requests; beautifulsoup4; click
42
- python_requires = >=3.0
43
- tests_require = pytest>=3
44
- include_package_data = 1
45
- packages = find:
46
- package_dir = =deep_translator
47
 
48
- [options.entry_points]
49
- console_scripts = deep-translator = __main__:deep_translator
50
- dt = __main__:deep_translator
51
 
52
- [options.packages.find]
53
- where = deep_translator
54
 
55
  # bumpversion config
56
  [bumpversion]
 
35
  YANDEX, MyMemory translator, Linguee, QCRI, Language, Language detection,
36
  detect language, free translation, unlimited translation, translate for free
37
 
38
+ # [options]
39
+ # zip_safe = 0
40
+ # setup_requires = pytest-runner
41
+ # install_requires = requests; beautifulsoup4; click
42
+ # python_requires = >=3.0
43
+ # tests_require = pytest>=3
44
+ # include_package_data = 1
45
+ # packages = find:
46
+ # package_dir = =deep_translator
47
 
48
+ # [options.entry_points]
49
+ # console_scripts = deep-translator = deep_translator.__main__:deep_translator
50
+ # dt = deep_translator.__main__:deep_translator
51
 
52
+ # [options.packages.find]
53
+ # where = deep_translator
54
 
55
  # bumpversion config
56
  [bumpversion]
setup.py ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # #!/usr/bin/env python
2
+ """The setup script."""
3
+ from setuptools import setup, find_packages
4
+
5
+ setup(
6
+ zip_safe=False,
7
+ setup_requires=['pytest-runner',],
8
+ install_requires=['requests','beautifulsoup4','click',],
9
+ python_requires='>=3',
10
+ tests_require=['pytest>=3',],
11
+ include_package_data=True,
12
+ packages=find_packages(include=['deep_translator'],),
13
+ entry_points={'console_scripts':[
14
+ 'deep-translator=deep_translator.__main__:main',
15
+ 'dt=deep_translator.__main__:main',
16
+ ],},
17
+ )
setup.py.bak DELETED
@@ -1,76 +0,0 @@
1
- # #!/usr/bin/env python
2
-
3
- # """The setup script."""
4
-
5
- # from setuptools import setup, find_packages
6
-
7
- # with open('README.rst') as readme_file:
8
- # readme = readme_file.read()
9
-
10
- # with open('HISTORY.rst') as history_file:
11
- # history = history_file.read()
12
-
13
-
14
- # # with open('./re') as reqs:
15
- # # requirements = reqs.read()
16
- # # print(requirements)
17
- # # exit()
18
- # setup_requirements = ['pytest-runner', ]
19
-
20
- # test_requirements = ['pytest>=3', ]
21
-
22
- # setup(
23
- # author="Nidhal Baccouri",
24
- # author_email='[email protected]',
25
- # maintainer="Nidhal Baccouri",
26
- # maintainer_email='[email protected]',
27
- # python_requires='>=3.0',
28
- # classifiers=[
29
- # 'Development Status :: 5 - Production/Stable',
30
- # 'Intended Audience :: Developers',
31
- # 'Intended Audience :: Education',
32
- # 'Intended Audience :: Information Technology',
33
- # 'License :: OSI Approved :: MIT License',
34
- # 'Topic :: Education',
35
- # 'Topic :: Software Development',
36
- # 'Topic :: Communications',
37
- # 'Topic :: Text Processing',
38
- # 'Topic :: Text Processing :: Linguistic',
39
- # 'Natural Language :: English',
40
- # 'Operating System :: OS Independent',
41
- # 'Programming Language :: Python :: 3',
42
- # 'Programming Language :: Python :: 3.5',
43
- # 'Programming Language :: Python :: 3.6',
44
- # 'Programming Language :: Python :: 3.7',
45
- # 'Programming Language :: Python :: 3.8',
46
- # ],
47
- # description="A flexible python tool to translate between different languages in a simple way.",
48
- # entry_points={
49
- # 'console_scripts': [
50
- # 'deep_translator = cli:main',
51
- # 'dt = cli:main',
52
- # ],
53
- # },
54
- # install_requires=['requests', 'beautifulsoup4', 'Click'],
55
- # license="MIT license",
56
- # long_description=readme + '\n\n' + history,
57
- # include_package_data=True,
58
- # keywords=['deep_translator',
59
- # 'deepL', 'DeepL',
60
- # 'translator',
61
- # 'translation',
62
- # 'automation',
63
- # 'web scraping',
64
- # 'google translator', 'google translation', 'google trans',
65
- # 'PONS', 'YANDEX', 'MyMemory translator', 'Linguee', 'QCRI',
66
- # 'Language', 'Language detection', 'detect language',
67
- # 'free translation', 'unlimited translation', 'translate for free'],
68
- # name='deep_translator',
69
- # packages=find_packages(include=['deep_translator']),
70
- # setup_requires=setup_requirements,
71
- # test_suite='tests',
72
- # tests_require=test_requirements,
73
- # url='https://github.com/nidhaloff/deep_translator',
74
- # version='1.4.4',
75
- # zip_safe=False,
76
- # )