Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async def detect_language(self, text: str, *, hint: list = None):
"""Detect language of text
:param text: text to detect language
:param hint: list of most likely possible languages"""
response = await self._make_request("detect", text=text, hint=hint)
code = response.get("code", 0)
if code != 200:
message = response.get("message")
if code == 401:
raise Exceptions.InvalidKey(message)
if code == 402:
raise Exceptions.KeyBlocked(message)
if code == 404:
raise Exceptions.DailyLimitExceeded(message)
raise Exceptions.UnknownException(message)
return response.get("lang", "")
async def detect_language(self, text: str, *, hint: list = None):
"""Detect language of text
:param text: text to detect language
:param hint: list of most likely possible languages"""
response = await self._make_request("detect", text=text, hint=hint)
code = response.get("code", 0)
if code != 200:
message = response.get("message")
if code == 401:
raise Exceptions.InvalidKey(message)
if code == 402:
raise Exceptions.KeyBlocked(message)
if code == 404:
raise Exceptions.DailyLimitExceeded(message)
raise Exceptions.UnknownException(message)
return response.get("lang", "")
async def get_translation(self, lang: str, text: str):
"""Get translation for list of strings
:param lang: language in format "fr-to" or "to"
:param text: string to translate"""
response = await self._make_request("translate", text=text, lang=lang)
code = response.get("code", 0)
if code != 200:
message = response.get("message")
if code == 401:
raise Exceptions.InvalidKey(message)
if code == 402:
raise Exceptions.KeyBlocked(message)
if code == 404:
raise Exceptions.DailyLimitExceeded(message)
if code == 413:
raise Exceptions.MaxTextLengthExceeded(message)
if code == 422:
raise Exceptions.UnableToTranslate(message)
if code == 501:
raise Exceptions.IncorrectLang(message)
raise Exceptions.UnknownException(message)
Translation = namedtuple("Translation", ["lang", "text"])
return Translation(response.get("lang", "??-??"), response.get("text", [""])[0])
:param lang: language in format "fr-to" or "to"
:param text: string to translate"""
response = await self._make_request("translate", text=text, lang=lang)
code = response.get("code", 0)
if code != 200:
message = response.get("message")
if code == 401:
raise Exceptions.InvalidKey(message)
if code == 402:
raise Exceptions.KeyBlocked(message)
if code == 404:
raise Exceptions.DailyLimitExceeded(message)
if code == 413:
raise Exceptions.MaxTextLengthExceeded(message)
if code == 422:
raise Exceptions.UnableToTranslate(message)
if code == 501:
raise Exceptions.IncorrectLang(message)
raise Exceptions.UnknownException(message)
Translation = namedtuple("Translation", ["lang", "text"])
return Translation(response.get("lang", "??-??"), response.get("text", [""])[0])
async def detect_language(self, text: str, *, hint: list = None):
"""Detect language of text
:param text: text to detect language
:param hint: list of most likely possible languages"""
response = await self._make_request("detect", text=text, hint=hint)
code = response.get("code", 0)
if code != 200:
message = response.get("message")
if code == 401:
raise Exceptions.InvalidKey(message)
if code == 402:
raise Exceptions.KeyBlocked(message)
if code == 404:
raise Exceptions.DailyLimitExceeded(message)
raise Exceptions.UnknownException(message)
return response.get("lang", "")
async def detect_language(self, text: str, *, hint: list = None):
"""Detect language of text
:param text: text to detect language
:param hint: list of most likely possible languages"""
response = await self._make_request("detect", text=text, hint=hint)
code = response.get("code", 0)
if code != 200:
message = response.get("message")
if code == 401:
raise Exceptions.InvalidKey(message)
if code == 402:
raise Exceptions.KeyBlocked(message)
if code == 404:
raise Exceptions.DailyLimitExceeded(message)
raise Exceptions.UnknownException(message)
return response.get("lang", "")
response = await self._make_request("translate", text=text, lang=lang)
code = response.get("code", 0)
if code != 200:
message = response.get("message")
if code == 401:
raise Exceptions.InvalidKey(message)
if code == 402:
raise Exceptions.KeyBlocked(message)
if code == 404:
raise Exceptions.DailyLimitExceeded(message)
if code == 413:
raise Exceptions.MaxTextLengthExceeded(message)
if code == 422:
raise Exceptions.UnableToTranslate(message)
if code == 501:
raise Exceptions.IncorrectLang(message)
raise Exceptions.UnknownException(message)
Translation = namedtuple("Translation", ["lang", "text"])
return Translation(response.get("lang", "??-??"), response.get("text", [""])[0])