def translate_exception(exc, locale): """Translates all translatable elements of the given exception.""" exc.message = gettextutils.translate(six.text_type(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 = six.text_type(exc) exc.detail = "" else: exc.explanation = gettextutils.translate(exc.explanation, locale) exc.detail = gettextutils.translate(exc.detail, locale) return exc
def translate_exception(exc, locale): """Translates all translatable elements of the given exception.""" exc.message = gettextutils.translate(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.translate(exc.explanation, locale) exc.detail = gettextutils.translate(exc.detail, locale) return exc