def __init__(self, timeout=10, source="auto", target="en", proxies={}, **kwargs): """ @param source: source language to translate from @param target: target language to translate to """ self.__base_url = BASE_URLS.get("MYMEMORY") if self.is_language_supported(source, target): self._source, self._target = self._map_language_to_code( source.lower(), target.lower()) self._source = self._source if self._source != 'auto' else 'Lao' self.email = kwargs.get('email', None) super(MyMemoryTranslator, self).__init__(base_url=self.__base_url, source=self._source, target=self._target, payload_key='q', langpair='{}|{}'.format(self._source, self._target), proxies=proxies, timeout=timeout)
def __init__(self, api_key=None, source="en", target="en", use_free_api=True, **kwargs): """ @param api_key: your DeepL api key. Get one here: https://www.deepl.com/docs-api/accessing-the-api/ @param source: source language @param target: target language """ if not api_key: raise ServerException(401) self.version = 'v2' self.api_key = api_key self.source = self._map_language_to_code(source) self.target = self._map_language_to_code(target) if use_free_api: self.__base_url = BASE_URLS.get("DEEPL_FREE").format(version=self.version) else: self.__base_url = BASE_URLS.get("DEEPL").format(version=self.version)
def __init__(self, api_key=None): """ @param api_key: your DeepL api key. Get one here: https://www.deepl.com/docs-api/accessing-the-api/ """ if not api_key: raise ServerException(401) self.version = 'v2' self.api_key = api_key self.__base_url = BASE_URLS.get("DEEPL").format(version=self.version)
def __init__(self, api_key=None): """ @param api_key: your yandex api key """ if not api_key: raise ServerException(401) self.__base_url = BASE_URLS.get("YANDEX") self.api_key = api_key self.api_version = "v1.5" self.api_endpoints = { "langs": "getLangs", "detect": "detect", "translate": "translate", }
def __init__(self, source="auto", target="en", **kwargs): """ @param source: source language to translate from @param target: target language to translate to """ self.__base_url = BASE_URLS.get("MYMEMORY") self._source = source if source != 'auto' else 'Lao' self._target = target self.email = kwargs.get('email', None) super(MyMemoryTranslator, self).__init__(base_url=self.__base_url, source=self._source, target=self._target, payload_key='q', langpair='{}|{}'.format(self._source, self._target))
def __init__(self, api_key=None, region=None, source=None, target=None, proxies=None, **kwargs): """ @params api_key and target are the required params @param api_key: your Microsoft API key @param region: your Microsoft Location """ if not api_key: raise ServerException(401) else: self.api_key = api_key self.proxies = proxies self.headers = { "Ocp-Apim-Subscription-Key": self.api_key, "Content-type": "application/json", } # region is not required but very common and goes to headers if passed if region: self.region = region self.headers["Ocp-Apim-Subscription-Region"] = self.region if not target: raise ServerException(401) else: if type(target) is str: self.target = target.lower() else: self.target = [i.lower() for i in target] if self.is_language_supported(self.target): self.target = self._map_language_to_code(self.target) self.url_params = {'to': self.target, **kwargs} if source: self.source = source.lower() if self.is_language_supported(self.source): self.source = self._map_language_to_code(self.source) self.url_params['from'] = self.source self.__base_url = BASE_URLS.get("MICROSOFT_TRANSLATE")
def __init__(self, source, target="english"): """ @param source: source language to translate from @param target: target language to translate to """ self.__base_url = BASE_URLS.get("PONS") if self.is_language_supported(source, target): self._source, self._target = self._map_language_to_code( source, target) super().__init__(base_url=self.__base_url, source=self._source, target=self._target, payload_key=None, element_tag='div', element_query={"class": "target"})
def __init__(self, source, target="en"): """ @param source: source language to translate from @param target: target language to translate to """ self.__base_url = BASE_URLS.get("LINGUEE") if self.is_language_supported(source, target): self._source, self._target = self._map_language_to_code(source.lower(), target.lower()) super().__init__(base_url=self.__base_url, source=self._source, target=self._target, element_tag='a', element_query={'class': 'dictLink featured'}, payload_key=None, # key of text in the url )
def __init__(self, api_key=None, source="en", target="en", **kwargs): """ @param api_key: your qrci api key. Get one for free here https://mt.qcri.org/api/v1/ref """ if not api_key: raise ServerException(401) self.__base_url = BASE_URLS.get("QCRI") self.source = source self.target = target self.api_key = api_key self.api_endpoints = { "get_languages": "getLanguagePairs", "get_domains": "getDomains", "translate": "translate", } self.params = {"key": self.api_key}
def __init__(self, source="auto", target="en"): """ @param source: source language to translate from @param target: target language to translate to """ self.__base_url = BASE_URLS.get("GOOGLE_TRANSLATE") if self.is_language_supported(source, target): self._source, self._target = self._map_language_to_code(source.lower(), target.lower()) super(GoogleTranslator, self).__init__(base_url=self.__base_url, source=self._source, target=self._target, element_tag='div', element_query={"class": "t0"}, payload_key='q', # key of text in the url hl=self._target, sl=self._source)
def __init__(self, client_id=None, secret_key=None, source="auto", target="en", **kwargs): """ @param source: source language to translate from @param target: target language to translate to """ if not client_id or not secret_key: raise Exception( "Please pass your client id and secret key! visit the papago website for more infos" ) self.__base_url = BASE_URLS.get("PAPAGO_API") self.client_id = client_id self.secret_key = secret_key if self.is_language_supported(source, target): self._source, self._target = self._map_language_to_code( source.lower(), target.lower())