nidhal baccouri commited on
Commit
f89616a
·
1 Parent(s): 5c85230

updated base urls

Browse files
deep_translator/__init__.py CHANGED
@@ -1,12 +1,12 @@
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
  from .papago import PapagoTranslator
@@ -23,8 +23,8 @@ __all__ = [
23
  "MyMemoryTranslator",
24
  "YandexTranslator",
25
  "MicrosoftTranslator",
26
- "QCRI",
27
- "DeepL",
28
  "LibreTranslator",
29
  "PapagoTranslator",
30
  "single_detection",
 
1
  """Top-level package for Deep Translator"""
2
 
3
+ from .google 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 QcriTranslator
9
+ from .deepl import DeeplTranslator
10
  from .detection import single_detection, batch_detection
11
  from .microsoft import MicrosoftTranslator
12
  from .papago import PapagoTranslator
 
23
  "MyMemoryTranslator",
24
  "YandexTranslator",
25
  "MicrosoftTranslator",
26
+ "QcriTranslator",
27
+ "DeeplTranslator",
28
  "LibreTranslator",
29
  "PapagoTranslator",
30
  "single_detection",
deep_translator/base.py CHANGED
@@ -24,7 +24,6 @@ class BaseTranslator(ABC):
24
  self._base_url = base_url
25
  self.languages: dict = GOOGLE_LANGUAGES_TO_CODES if not languages else languages
26
  self.supported_languages: list = list(self.languages.keys())
27
-
28
  self._source, self._target = self._map_language_to_code(source, target)
29
  self._url_params = url_params
30
  self._element_tag = element_tag
 
24
  self._base_url = base_url
25
  self.languages: dict = GOOGLE_LANGUAGES_TO_CODES if not languages else languages
26
  self.supported_languages: list = list(self.languages.keys())
 
27
  self._source, self._target = self._map_language_to_code(source, target)
28
  self._url_params = url_params
29
  self._element_tag = element_tag
deep_translator/constants.py CHANGED
@@ -6,7 +6,7 @@ BASE_URLS = {
6
  "YANDEX": "https://translate.yandex.net/api/{version}/tr.json/{endpoint}",
7
  "LINGUEE": "https://www.linguee.com/",
8
  "MYMEMORY": "http://api.mymemory.translated.net/get",
9
- "QCRI": "https://mt.qcri.org/api/v1/{endpoint}?",
10
  "DEEPL": "https://api.deepl.com/{version}/",
11
  "DEEPL_FREE": "https://api-free.deepl.com/v2/",
12
  "MICROSOFT_TRANSLATE": "https://api.cognitive.microsofttranslator.com/translate?api-version=3.0",
 
6
  "YANDEX": "https://translate.yandex.net/api/{version}/tr.json/{endpoint}",
7
  "LINGUEE": "https://www.linguee.com/",
8
  "MYMEMORY": "http://api.mymemory.translated.net/get",
9
+ "QcriTranslator": "https://mt.qcri.org/api/v1/{endpoint}?",
10
  "DEEPL": "https://api.deepl.com/{version}/",
11
  "DEEPL_FREE": "https://api-free.deepl.com/v2/",
12
  "MICROSOFT_TRANSLATE": "https://api.cognitive.microsofttranslator.com/translate?api-version=3.0",
deep_translator/deepl.py CHANGED
@@ -8,14 +8,14 @@ from .exceptions import (ServerException,
8
  from .base import BaseTranslator
9
 
10
 
11
- class DeepL(BaseTranslator):
12
  """
13
- class that wraps functions, which use the DeepL translator under the hood to translate word(s)
14
  """
15
 
16
  def __init__(self, api_key=None, source="de", target="en", use_free_api=True, **kwargs):
17
  """
18
- @param api_key: your DeepL api key.
19
  Get one here: https://www.deepl.com/docs-api/accessing-the-api/
20
  @param source: source language
21
  @param target: target language
@@ -80,6 +80,6 @@ class DeepL(BaseTranslator):
80
 
81
 
82
  if __name__ == '__main__':
83
- d = DeepL(target="de")
84
  t = d.translate("I have no idea")
85
  print("text: ", t)
 
8
  from .base import BaseTranslator
9
 
10
 
11
+ class DeeplTranslator(BaseTranslator):
12
  """
13
+ class that wraps functions, which use the DeeplTranslator translator under the hood to translate word(s)
14
  """
15
 
16
  def __init__(self, api_key=None, source="de", target="en", use_free_api=True, **kwargs):
17
  """
18
+ @param api_key: your DeeplTranslator api key.
19
  Get one here: https://www.deepl.com/docs-api/accessing-the-api/
20
  @param source: source language
21
  @param target: target language
 
80
 
81
 
82
  if __name__ == '__main__':
83
+ d = DeeplTranslator(target="de")
84
  t = d.translate("I have no idea")
85
  print("text: ", t)
deep_translator/{google_trans.py → google.py} RENAMED
File without changes
deep_translator/libre.py CHANGED
@@ -8,8 +8,8 @@ from .validate import is_empty
8
  from .base import BaseTranslator
9
  from .constants import BASE_URLS,LIBRE_LANGUAGES_TO_CODES
10
  from .exceptions import (ServerException,
11
- TranslationNotFound,
12
- AuthorizationException)
13
 
14
 
15
  class LibreTranslator(BaseTranslator):
@@ -26,9 +26,9 @@ class LibreTranslator(BaseTranslator):
26
  """
27
  if not api_key:
28
  raise ServerException(401)
29
- self._base_url = BASE_URLS.get("LIBRE")
30
  self.api_key = api_key
31
- super().__init__(source=source,
 
32
  target=target,
33
  languages=LIBRE_LANGUAGES_TO_CODES)
34
 
 
8
  from .base import BaseTranslator
9
  from .constants import BASE_URLS,LIBRE_LANGUAGES_TO_CODES
10
  from .exceptions import (ServerException,
11
+ TranslationNotFound,
12
+ AuthorizationException)
13
 
14
 
15
  class LibreTranslator(BaseTranslator):
 
26
  """
27
  if not api_key:
28
  raise ServerException(401)
 
29
  self.api_key = api_key
30
+ super().__init__(base_url=BASE_URLS.get("LIBRE"),
31
+ source=source,
32
  target=target,
33
  languages=LIBRE_LANGUAGES_TO_CODES)
34
 
deep_translator/linguee.py CHANGED
@@ -25,9 +25,8 @@ class LingueeTranslator(BaseTranslator):
25
  @param source: source language to translate from
26
  @param target: target language to translate to
27
  """
28
- self._base_url = BASE_URLS.get("LINGUEE")
29
  self.proxies = proxies
30
- super().__init__(base_url=self._base_url,
31
  source=source,
32
  target=target,
33
  languages=LINGUEE_LANGUAGES_TO_CODES,
 
25
  @param source: source language to translate from
26
  @param target: target language to translate to
27
  """
 
28
  self.proxies = proxies
29
+ super().__init__(base_url=BASE_URLS.get("LINGUEE"),
30
  source=source,
31
  target=target,
32
  languages=LINGUEE_LANGUAGES_TO_CODES,
deep_translator/microsoft.py CHANGED
@@ -35,8 +35,8 @@ class MicrosoftTranslator(BaseTranslator):
35
  if region:
36
  self.region = region
37
  self.headers["Ocp-Apim-Subscription-Region"] = self.region
38
- self._base_url = BASE_URLS.get("MICROSOFT_TRANSLATE")
39
  super().__init__(
 
40
  source=source,
41
  target=target,
42
  languages=MICROSOFT_CODES_TO_LANGUAGES,
 
35
  if region:
36
  self.region = region
37
  self.headers["Ocp-Apim-Subscription-Region"] = self.region
 
38
  super().__init__(
39
+ base_url=BASE_URLS.get("MICROSOFT_TRANSLATE"),
40
  source=source,
41
  target=target,
42
  languages=MICROSOFT_CODES_TO_LANGUAGES,
deep_translator/mymemory.py CHANGED
@@ -20,10 +20,9 @@ class MyMemoryTranslator(BaseTranslator):
20
  @param source: source language to translate from
21
  @param target: target language to translate to
22
  """
23
- self._base_url = BASE_URLS.get("MYMEMORY")
24
  self.proxies = proxies
25
  self.email = kwargs.get('email', None)
26
- super(MyMemoryTranslator, self).__init__(base_url=self._base_url,
27
  source=self._source,
28
  target=self._target,
29
  payload_key='q',
 
20
  @param source: source language to translate from
21
  @param target: target language to translate to
22
  """
 
23
  self.proxies = proxies
24
  self.email = kwargs.get('email', None)
25
+ super(MyMemoryTranslator, self).__init__(base_url=BASE_URLS.get("MYMEMORY"),
26
  source=self._source,
27
  target=self._target,
28
  payload_key='q',
deep_translator/papago.py CHANGED
@@ -22,10 +22,10 @@ class PapagoTranslator(BaseTranslator):
22
  raise Exception(
23
  "Please pass your client id and secret key! visit the papago website for more infos")
24
 
25
- self._base_url = BASE_URLS.get("PAPAGO_API")
26
  self.client_id = client_id
27
  self.secret_key = secret_key
28
  super().__init__(
 
29
  source=source,
30
  target=target,
31
  languages=PAPAGO_LANGUAGE_TO_CODE,
 
22
  raise Exception(
23
  "Please pass your client id and secret key! visit the papago website for more infos")
24
 
 
25
  self.client_id = client_id
26
  self.secret_key = secret_key
27
  super().__init__(
28
+ base_url=BASE_URLS.get("PAPAGO_API"),
29
  source=source,
30
  target=target,
31
  languages=PAPAGO_LANGUAGE_TO_CODE,
deep_translator/pons.py CHANGED
@@ -26,9 +26,8 @@ class PonsTranslator(BaseTranslator):
26
  @param source: source language to translate from
27
  @param target: target language to translate to
28
  """
29
- self._base_url = BASE_URLS.get("PONS")
30
  self.proxies = proxies
31
- super().__init__(base_url=self._base_url,
32
  languages=PONS_CODES_TO_LANGUAGES,
33
  source=source,
34
  target=target,
 
26
  @param source: source language to translate from
27
  @param target: target language to translate to
28
  """
 
29
  self.proxies = proxies
30
+ super().__init__(base_url=BASE_URLS.get("PONS"),
31
  languages=PONS_CODES_TO_LANGUAGES,
32
  source=source,
33
  target=target,
deep_translator/qcri.py CHANGED
@@ -5,7 +5,7 @@ from .exceptions import (ServerException, TranslationNotFound)
5
  from .base import BaseTranslator
6
 
7
 
8
- class QCRI(BaseTranslator):
9
  """
10
  class that wraps functions, which use the QRCI translator under the hood to translate word(s)
11
  """
@@ -17,7 +17,6 @@ class QCRI(BaseTranslator):
17
 
18
  if not api_key:
19
  raise ServerException(401)
20
- self._base_url = BASE_URLS.get("QCRI")
21
  self.api_key = api_key
22
  self.api_endpoints = {
23
  "get_languages": "getLanguagePairs",
@@ -29,6 +28,7 @@ class QCRI(BaseTranslator):
29
  "key": self.api_key
30
  }
31
  super().__init__(
 
32
  source=source,
33
  target=target,
34
  languages=QCRI_LANGUAGE_TO_CODE,
 
5
  from .base import BaseTranslator
6
 
7
 
8
+ class QcriTranslator(BaseTranslator):
9
  """
10
  class that wraps functions, which use the QRCI translator under the hood to translate word(s)
11
  """
 
17
 
18
  if not api_key:
19
  raise ServerException(401)
 
20
  self.api_key = api_key
21
  self.api_endpoints = {
22
  "get_languages": "getLanguagePairs",
 
28
  "key": self.api_key
29
  }
30
  super().__init__(
31
+ base_url=BASE_URLS.get("QcriTranslator"),
32
  source=source,
33
  target=target,
34
  languages=QCRI_LANGUAGE_TO_CODE,
deep_translator/yandex.py CHANGED
@@ -19,7 +19,6 @@ class YandexTranslator(BaseTranslator):
19
  """
20
  if not api_key:
21
  raise ServerException(401)
22
- self._base_url = BASE_URLS.get("YANDEX")
23
  self.api_key = api_key
24
  self.api_version = "v1.5"
25
  self.api_endpoints = {
@@ -28,6 +27,7 @@ class YandexTranslator(BaseTranslator):
28
  "translate": "translate",
29
  }
30
  super().__init__(
 
31
  source=source,
32
  target=target,
33
  **kwargs
 
19
  """
20
  if not api_key:
21
  raise ServerException(401)
 
22
  self.api_key = api_key
23
  self.api_version = "v1.5"
24
  self.api_endpoints = {
 
27
  "translate": "translate",
28
  }
29
  super().__init__(
30
+ base_url=BASE_URLS.get("YANDEX"),
31
  source=source,
32
  target=target,
33
  **kwargs
docs/README.rst CHANGED
@@ -106,8 +106,8 @@ Features
106
  * Support for the `Linguee translator <https://www.linguee.com/>`_
107
  * Support for the `Mymemory translator <https://mymemory.translated.net/>`_
108
  * Support for the `Yandex translator <https://yandex.com/>`_ (version >= 1.2.1)
109
- * Support for the `QCRI translator <https://mt.qcri.org/api/>`_ (version >= 1.2.4)
110
- * Support for the `DeepL translator <https://www.deepl.com/en/translator/>`_ (version >= 1.2.5)
111
  * Support for the `Papago translator <https://papago.naver.com/>`_ (version >= 1.4.4)
112
  * Support for the `Libre translator <https://libretranslate.com/>`_
113
  * Support for proxy usage
@@ -187,8 +187,8 @@ Imports
187
  MyMemoryTranslator,
188
  YandexTranslator,
189
  PapagoTranslator,
190
- DeepL,
191
- QCRI,
192
  single_detection,
193
  batch_detection)
194
 
@@ -306,12 +306,12 @@ Mymemory Translator
306
  translated = MyMemoryTranslator(source='en', target='fr').translate_file(path)
307
 
308
 
309
- DeepL Translator
310
  -----------------
311
 
312
  .. note::
313
 
314
- In order to use the DeepL translator, you need to generate an api key. Deepl offers a Pro and a free API.
315
  deep-translator supports both Pro and free APIs. Just check the examples below.
316
  Visit https://www.deepl.com/en/docs-api/ for more information on how to generate your Deepl api key
317
 
@@ -321,7 +321,7 @@ DeepL Translator
321
 
322
  text = 'Keep it up. You are awesome'
323
 
324
- translated = DeepL(api_key="your_api_key", source="en", target="en", use_free_api=True).translate(text)
325
 
326
  .. note::
327
  deep-translator uses free deepl api by default. If you have the pro version then simply set the use_free_api to false.
@@ -334,14 +334,14 @@ DeepL Translator
334
  texts = ["hallo welt", "guten morgen"]
335
 
336
  # the translate_sentences function is deprecated, use the translate_batch function instead
337
- translated = DeepL("your_api_key").translate_batch(texts)
338
 
339
- QCRI Translator
340
  --------------------
341
 
342
  .. note::
343
 
344
- In order to use the QCRI translator, you need to generate a free api key. Visit https://mt.qcri.org/api/
345
  for more information
346
 
347
  - Check languages
@@ -349,14 +349,14 @@ QCRI Translator
349
  .. code-block:: python
350
 
351
  # as a property
352
- print("language pairs: ", QCRI("your_api_key").languages)
353
 
354
  - Check domains
355
 
356
  .. code-block:: python
357
 
358
  # as a property
359
- print("domains: ", QCRI("your_api_key").domains)
360
 
361
  - Text translation
362
 
@@ -364,7 +364,7 @@ QCRI Translator
364
 
365
  text = 'Education is great'
366
 
367
- translated = QCRI("your_api_key").translate(source='en', target='ar', domain="news", text=text)
368
  # output -> التعليم هو عظيم
369
 
370
  # see docs for batch translation and more.
 
106
  * Support for the `Linguee translator <https://www.linguee.com/>`_
107
  * Support for the `Mymemory translator <https://mymemory.translated.net/>`_
108
  * Support for the `Yandex translator <https://yandex.com/>`_ (version >= 1.2.1)
109
+ * Support for the `QcriTranslator translator <https://mt.qcri.org/api/>`_ (version >= 1.2.4)
110
+ * Support for the `DeeplTranslator translator <https://www.deepl.com/en/translator/>`_ (version >= 1.2.5)
111
  * Support for the `Papago translator <https://papago.naver.com/>`_ (version >= 1.4.4)
112
  * Support for the `Libre translator <https://libretranslate.com/>`_
113
  * Support for proxy usage
 
187
  MyMemoryTranslator,
188
  YandexTranslator,
189
  PapagoTranslator,
190
+ DeeplTranslator,
191
+ QcriTranslator,
192
  single_detection,
193
  batch_detection)
194
 
 
306
  translated = MyMemoryTranslator(source='en', target='fr').translate_file(path)
307
 
308
 
309
+ DeeplTranslator Translator
310
  -----------------
311
 
312
  .. note::
313
 
314
+ In order to use the DeeplTranslator translator, you need to generate an api key. Deepl offers a Pro and a free API.
315
  deep-translator supports both Pro and free APIs. Just check the examples below.
316
  Visit https://www.deepl.com/en/docs-api/ for more information on how to generate your Deepl api key
317
 
 
321
 
322
  text = 'Keep it up. You are awesome'
323
 
324
+ translated = DeeplTranslator(api_key="your_api_key", source="en", target="en", use_free_api=True).translate(text)
325
 
326
  .. note::
327
  deep-translator uses free deepl api by default. If you have the pro version then simply set the use_free_api to false.
 
334
  texts = ["hallo welt", "guten morgen"]
335
 
336
  # the translate_sentences function is deprecated, use the translate_batch function instead
337
+ translated = DeeplTranslator("your_api_key").translate_batch(texts)
338
 
339
+ QcriTranslator Translator
340
  --------------------
341
 
342
  .. note::
343
 
344
+ In order to use the QcriTranslator translator, you need to generate a free api key. Visit https://mt.qcri.org/api/
345
  for more information
346
 
347
  - Check languages
 
349
  .. code-block:: python
350
 
351
  # as a property
352
+ print("language pairs: ", QcriTranslator("your_api_key").languages)
353
 
354
  - Check domains
355
 
356
  .. code-block:: python
357
 
358
  # as a property
359
+ print("domains: ", QcriTranslator("your_api_key").domains)
360
 
361
  - Text translation
362
 
 
364
 
365
  text = 'Education is great'
366
 
367
+ translated = QcriTranslator("your_api_key").translate(source='en', target='ar', domain="news", text=text)
368
  # output -> التعليم هو عظيم
369
 
370
  # see docs for batch translation and more.
docs/history.rst CHANGED
@@ -11,8 +11,8 @@ Important History
11
  - 1.3.4 bug fixes for the dutch language
12
  - 1.3.3 fixed bug in google translate
13
 
14
- - 1.2.5: added support for the DeepL translator
15
- - 1.2.4: added support for the QCRI translator
16
  - 1.2.1: added support for the yandex translator
17
  - 1.1.9: fixed bug in requests
18
  - 1.1.5: added language detection
 
11
  - 1.3.4 bug fixes for the dutch language
12
  - 1.3.3 fixed bug in google translate
13
 
14
+ - 1.2.5: added support for the DeeplTranslator translator
15
+ - 1.2.4: added support for the QcriTranslator translator
16
  - 1.2.1: added support for the yandex translator
17
  - 1.1.9: fixed bug in requests
18
  - 1.1.5: added language detection
docs/modules.rst CHANGED
@@ -20,7 +20,7 @@ Exceptions
20
  :undoc-members:
21
  :show-inheritance:
22
 
23
-
24
  Language Detection Library
25
  ----------------------------------
26
 
@@ -40,7 +40,7 @@ Google Translator
40
  :undoc-members:
41
  :show-inheritance:
42
 
43
- DeepL
44
  ----------------------------------
45
 
46
  .. automodule:: deep_translator.deepl
@@ -88,7 +88,7 @@ Pons
88
  :undoc-members:
89
  :show-inheritance:
90
 
91
- QCRI
92
  ----------------------------------
93
 
94
  .. automodule:: deep_translator.qcri
@@ -102,4 +102,4 @@ Yandex
102
  .. automodule:: deep_translator.yandex
103
  :members:
104
  :undoc-members:
105
- :show-inheritance:
 
20
  :undoc-members:
21
  :show-inheritance:
22
 
23
+
24
  Language Detection Library
25
  ----------------------------------
26
 
 
40
  :undoc-members:
41
  :show-inheritance:
42
 
43
+ DeeplTranslator
44
  ----------------------------------
45
 
46
  .. automodule:: deep_translator.deepl
 
88
  :undoc-members:
89
  :show-inheritance:
90
 
91
+ QcriTranslator
92
  ----------------------------------
93
 
94
  .. automodule:: deep_translator.qcri
 
102
  .. automodule:: deep_translator.yandex
103
  :members:
104
  :undoc-members:
105
+ :show-inheritance:
docs/usage.rst CHANGED
@@ -22,8 +22,8 @@ Imports
22
  LingueeTranslator,
23
  MyMemoryTranslator,
24
  YandexTranslator,
25
- DeepL,
26
- QCRI,
27
  single_detection,
28
  batch_detection)
29
 
@@ -140,12 +140,12 @@ Mymemory Translator
140
  translated = MyMemoryTranslator(source='en', target='fr').translate_file(path)
141
 
142
 
143
- DeepL Translator
144
  -----------------
145
 
146
  .. note::
147
 
148
- In order to use the DeepL translator, you need to generate an api key. Visit https://www.deepl.com/en/docs-api/
149
  for more information
150
 
151
  - Simple translation
@@ -154,7 +154,7 @@ DeepL Translator
154
 
155
  text = 'Keep it up. You are awesome'
156
 
157
- translated = DeepL("your_api_key").translate(text)
158
 
159
  - Translate batch of texts
160
 
@@ -163,14 +163,14 @@ DeepL Translator
163
  texts = ["hallo welt", "guten morgen"]
164
 
165
  # the translate_sentences function is deprecated, use the translate_batch function instead
166
- translated = DeepL("your_api_key").translate_batch(texts)
167
 
168
- QCRI Translator
169
  --------------------
170
 
171
  .. note::
172
 
173
- In order to use the QCRI translator, you need to generate a free api key. Visit https://mt.qcri.org/api/
174
  for more information
175
 
176
  - Check languages
@@ -178,14 +178,14 @@ QCRI Translator
178
  .. code-block:: python
179
 
180
  # as a property
181
- print("language pairs: ", QCRI("your_api_key").languages)
182
 
183
  - Check domains
184
 
185
  .. code-block:: python
186
 
187
  # as a property
188
- print("domains: ", QCRI("your_api_key").domains)
189
 
190
  - Text translation
191
 
@@ -193,7 +193,7 @@ QCRI Translator
193
 
194
  text = 'Education is great'
195
 
196
- translated = QCRI("your_api_key").translate(source='en', target='ar', domain="news", text=text)
197
  # output -> التعليم هو عظيم
198
 
199
  # see docs for batch translation and more.
@@ -306,7 +306,7 @@ Libre Translator
306
  .. note::
307
 
308
  Libre translate has multiple `mirrors <https://github.com/LibreTranslate/LibreTranslate#mirrors>`_ which can be used for the API endpoint.
309
- Some require an API key to be used. By default the base url is set to `libretranslate.de <https://libretranslate.de/>`_ .
310
  This can be set using the "base_url" input parameter.
311
 
312
  .. code-block:: python
 
22
  LingueeTranslator,
23
  MyMemoryTranslator,
24
  YandexTranslator,
25
+ DeeplTranslator,
26
+ QcriTranslator,
27
  single_detection,
28
  batch_detection)
29
 
 
140
  translated = MyMemoryTranslator(source='en', target='fr').translate_file(path)
141
 
142
 
143
+ DeeplTranslator Translator
144
  -----------------
145
 
146
  .. note::
147
 
148
+ In order to use the DeeplTranslator translator, you need to generate an api key. Visit https://www.deepl.com/en/docs-api/
149
  for more information
150
 
151
  - Simple translation
 
154
 
155
  text = 'Keep it up. You are awesome'
156
 
157
+ translated = DeeplTranslator("your_api_key").translate(text)
158
 
159
  - Translate batch of texts
160
 
 
163
  texts = ["hallo welt", "guten morgen"]
164
 
165
  # the translate_sentences function is deprecated, use the translate_batch function instead
166
+ translated = DeeplTranslator("your_api_key").translate_batch(texts)
167
 
168
+ QcriTranslator Translator
169
  --------------------
170
 
171
  .. note::
172
 
173
+ In order to use the QcriTranslator translator, you need to generate a free api key. Visit https://mt.qcri.org/api/
174
  for more information
175
 
176
  - Check languages
 
178
  .. code-block:: python
179
 
180
  # as a property
181
+ print("language pairs: ", QcriTranslator("your_api_key").languages)
182
 
183
  - Check domains
184
 
185
  .. code-block:: python
186
 
187
  # as a property
188
+ print("domains: ", QcriTranslator("your_api_key").domains)
189
 
190
  - Text translation
191
 
 
193
 
194
  text = 'Education is great'
195
 
196
+ translated = QcriTranslator("your_api_key").translate(source='en', target='ar', domain="news", text=text)
197
  # output -> التعليم هو عظيم
198
 
199
  # see docs for batch translation and more.
 
306
  .. note::
307
 
308
  Libre translate has multiple `mirrors <https://github.com/LibreTranslate/LibreTranslate#mirrors>`_ which can be used for the API endpoint.
309
+ Some require an API key to be used. By default the base url is set to `libretranslate.de <https://libretranslate.de/>`_ .
310
  This can be set using the "base_url" input parameter.
311
 
312
  .. code-block:: python
pyproject.toml CHANGED
@@ -9,7 +9,7 @@ readme = "docs/README.rst"
9
  homepage = "https://github.com/nidhaloff/deep_translator"
10
  repository = "https://github.com/nidhaloff/deep_translator"
11
  documentation = "https://deep-translator.readthedocs.io/en/latest/"
12
- keywords = ["deep_translator", "deepL", "DeepL", "translator", "translation", "automation", "web scraping", "google translator", "google translation", "google trans", "PONS", "YANDEX", "MyMemory translator", "Linguee", "QCRI", "Language", "Language detection", "detect language", "free translation", "unlimited translation", "translate for free"]
13
  classifiers = [
14
  "Development Status :: 5 - Production/Stable",
15
  "Intended Audience :: Developers",
 
9
  homepage = "https://github.com/nidhaloff/deep_translator"
10
  repository = "https://github.com/nidhaloff/deep_translator"
11
  documentation = "https://deep-translator.readthedocs.io/en/latest/"
12
+ keywords = ["deep_translator", "deepL", "DeeplTranslator", "translator", "translation", "automation", "web scraping", "google translator", "google translation", "google trans", "PONS", "YANDEX", "MyMemory translator", "Linguee", "QcriTranslator", "Language", "Language detection", "detect language", "free translation", "unlimited translation", "translate for free"]
13
  classifiers = [
14
  "Development Status :: 5 - Production/Stable",
15
  "Intended Audience :: Developers",
tests/test_deepl.py CHANGED
@@ -1,12 +1,12 @@
1
  import pytest
2
  from unittest.mock import Mock, PropertyMock, patch
3
- from deep_translator.deepl import DeepL
4
  from deep_translator.exceptions import AuthorizationException
5
 
6
 
7
  @patch('deep_translator.deepl.requests')
8
  def test_simple_translation(mock_requests):
9
- translator = DeepL(api_key='imagine-this-is-an-valid-api-key', source='en', target='es')
10
  # Set the request response mock.
11
  mock_response = Mock()
12
  mock_response.status_code = 200
@@ -22,7 +22,7 @@ def test_simple_translation(mock_requests):
22
 
23
  @patch('deep_translator.deepl.requests.get')
24
  def test_wrong_api_key(mock_requests):
25
- translator = DeepL(api_key='this-is-a-wrong-api-key!', source="en", target="es")
26
  # Set the response status_code only.
27
  mock_requests.return_value = Mock(status_code=403)
28
  with pytest.raises(AuthorizationException):
 
1
  import pytest
2
  from unittest.mock import Mock, PropertyMock, patch
3
+ from deep_translator.deepl import DeeplTranslator
4
  from deep_translator.exceptions import AuthorizationException
5
 
6
 
7
  @patch('deep_translator.deepl.requests')
8
  def test_simple_translation(mock_requests):
9
+ translator = DeeplTranslator(api_key='imagine-this-is-an-valid-api-key', source='en', target='es')
10
  # Set the request response mock.
11
  mock_response = Mock()
12
  mock_response.status_code = 200
 
22
 
23
  @patch('deep_translator.deepl.requests.get')
24
  def test_wrong_api_key(mock_requests):
25
+ translator = DeeplTranslator(api_key='this-is-a-wrong-api-key!', source="en", target="es")
26
  # Set the response status_code only.
27
  mock_requests.return_value = Mock(status_code=403)
28
  with pytest.raises(AuthorizationException):