nidhal baccouri
commited on
Commit
·
97bacde
1
Parent(s):
b1f5dde
structure papago api
Browse files- deep_translator/papago.py +4 -14
deep_translator/papago.py
CHANGED
|
@@ -12,34 +12,24 @@ import warnings
|
|
| 12 |
import logging
|
| 13 |
|
| 14 |
|
| 15 |
-
class PapagoTranslator(
|
| 16 |
"""
|
| 17 |
class that wraps functions, which use google translate under the hood to translate text(s)
|
| 18 |
"""
|
| 19 |
_languages = PAPAGO_LANGUAGE_TO_CODE
|
| 20 |
supported_languages = list(_languages.keys())
|
| 21 |
|
| 22 |
-
def __init__(self, source="auto", target="en"
|
| 23 |
"""
|
| 24 |
@param source: source language to translate from
|
| 25 |
@param target: target language to translate to
|
| 26 |
"""
|
| 27 |
self.__base_url = BASE_URLS.get("PAPAGO_API")
|
| 28 |
-
self.
|
| 29 |
-
|
| 30 |
if self.is_language_supported(source, target):
|
| 31 |
self._source, self._target = self._map_language_to_code(source.lower(), target.lower())
|
| 32 |
|
| 33 |
-
super(PapagoTranslator, self).__init__(base_url=self.__base_url,
|
| 34 |
-
source=self._source,
|
| 35 |
-
target=self._target,
|
| 36 |
-
element_tag='div',
|
| 37 |
-
element_query={"id": "txtTarget"},
|
| 38 |
-
payload_key='st', # key of text in the url
|
| 39 |
-
tk=self._target,
|
| 40 |
-
sk=self._source,
|
| 41 |
-
**kwargs)
|
| 42 |
-
|
| 43 |
@staticmethod
|
| 44 |
def get_supported_languages(as_dict=False):
|
| 45 |
"""
|
|
|
|
| 12 |
import logging
|
| 13 |
|
| 14 |
|
| 15 |
+
class PapagoTranslator(object):
|
| 16 |
"""
|
| 17 |
class that wraps functions, which use google translate under the hood to translate text(s)
|
| 18 |
"""
|
| 19 |
_languages = PAPAGO_LANGUAGE_TO_CODE
|
| 20 |
supported_languages = list(_languages.keys())
|
| 21 |
|
| 22 |
+
def __init__(self, client_id, secret_key, source="auto", target="en"):
|
| 23 |
"""
|
| 24 |
@param source: source language to translate from
|
| 25 |
@param target: target language to translate to
|
| 26 |
"""
|
| 27 |
self.__base_url = BASE_URLS.get("PAPAGO_API")
|
| 28 |
+
self.client_id = client_id
|
| 29 |
+
self.secret_key = secret_key
|
| 30 |
if self.is_language_supported(source, target):
|
| 31 |
self._source, self._target = self._map_language_to_code(source.lower(), target.lower())
|
| 32 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
@staticmethod
|
| 34 |
def get_supported_languages(as_dict=False):
|
| 35 |
"""
|