Example #1
0
def translate_exception(exc, locale):
    """Translates all translatable elements of the given exception."""
    exc.message = gettextutils.get_localized_message(exc.message, locale)
    if isinstance(exc, webob.exc.HTTPError):
        # If the explanation is not a Message, that means that the
        # explanation is the default, generic and not translatable explanation
        # from webop.exc. Since the explanation is the error shown when the
        # exception is converted to a response, let's actually swap it with
        # message, since message is what gets passed in at construction time
        # in the API
        if not isinstance(exc.explanation, gettextutils.Message):
            exc.explanation = exc.message
            exc.detail = ""
        else:
            exc.explanation = gettextutils.get_localized_message(exc.explanation, locale)
            exc.detail = gettextutils.get_localized_message(exc.detail, locale)
    return exc
Example #2
0
def translate_exception(exc, locale):
    """Translates all translatable elements of the given exception."""
    exc.message = gettextutils.get_localized_message(str(exc), locale)
    if isinstance(exc, webob.exc.HTTPError):
        # If the explanation is not a Message, that means that the
        # explanation is the default, generic and not translatable explanation
        # from webop.exc. Since the explanation is the error shown when the
        # exception is converted to a response, let's actually swap it with
        # message, since message is what gets passed in at construction time
        # in the API
        if not isinstance(exc.explanation, gettextutils.Message):
            exc.explanation = str(exc)
            exc.detail = ''
        else:
            exc.explanation = \
                gettextutils.get_localized_message(exc.explanation, locale)
            exc.detail = gettextutils.get_localized_message(exc.detail, locale)
    return exc