Avoid using private class from oslo.i18n
Use oslo.i18n.translate() without first testing if the argument being passed is a Message instance. The Message class is meant to be hidden from consumers, and translate() correctly detects untranslatable strings and returns them as given.
This commit is contained in:
parent
b184697234
commit
d847bbdb13
@ -665,19 +665,8 @@ def translate_exception(exc, locale):
|
||||
exc.message = i18n.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, i18n._message.Message):
|
||||
exc.explanation = six.text_type(exc)
|
||||
exc.detail = ''
|
||||
else:
|
||||
exc.explanation = \
|
||||
i18n.translate(exc.explanation, locale)
|
||||
exc.detail = i18n.translate(exc.detail, locale)
|
||||
exc.explanation = i18n.translate(exc.explanation, locale)
|
||||
exc.detail = i18n.translate(getattr(exc, 'detail', ''), locale)
|
||||
return exc
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user