How to use the translators.yandextranslate.Exceptions function in translators

To help you get started, we’ve selected a few translators examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github fixator10 / Fixator10-Cogs / translators / yandextranslate.py View on Github external
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", "")
github fixator10 / Fixator10-Cogs / translators / yandextranslate.py View on Github external
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", "")
github fixator10 / Fixator10-Cogs / translators / yandextranslate.py View on Github external
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])
github fixator10 / Fixator10-Cogs / translators / yandextranslate.py View on Github external
: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])
github fixator10 / Fixator10-Cogs / translators / yandextranslate.py View on Github external
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", "")
github fixator10 / Fixator10-Cogs / translators / yandextranslate.py View on Github external
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", "")
github fixator10 / Fixator10-Cogs / translators / yandextranslate.py View on Github external
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])