Re-enable lazy translation

After enhancements to Oslo Message class, re-enable lazy translation to
enable REST API responses to be translated to the requested user locale.

bp i18n-messages

Change-Id: I15ecffd678393c27c34336035d37915655e9f350
This commit is contained in:
cbjchen@cn.ibm.com 2014-01-25 23:13:03 +08:00 committed by Gerrit Code Review
parent 26fe7a961f
commit fa133569a4
6 changed files with 14 additions and 7 deletions

View File

@ -33,7 +33,8 @@ if os.path.exists(os.path.join(possible_topdir, 'heat', '__init__.py')):
from heat.openstack.common import gettextutils
gettextutils.install('heat', lazy=False)
gettextutils.enable_lazy()
gettextutils.install('heat', lazy=True)
from oslo.config import cfg

View File

@ -35,7 +35,8 @@ if os.path.exists(os.path.join(possible_topdir, 'heat', '__init__.py')):
from heat.openstack.common import gettextutils
gettextutils.install('heat', lazy=False)
gettextutils.enable_lazy()
gettextutils.install('heat', lazy=True)
from oslo.config import cfg

View File

@ -35,7 +35,8 @@ if os.path.exists(os.path.join(possible_topdir, 'heat', '__init__.py')):
from heat.openstack.common import gettextutils
gettextutils.install('heat', lazy=False)
gettextutils.enable_lazy()
gettextutils.install('heat', lazy=True)
from oslo.config import cfg

View File

@ -36,7 +36,8 @@ if os.path.exists(os.path.join(POSSIBLE_TOPDIR, 'heat', '__init__.py')):
from heat.openstack.common import gettextutils
gettextutils.install('heat', lazy=False)
gettextutils.enable_lazy()
gettextutils.install('heat', lazy=True)
from oslo.config import cfg

View File

@ -119,11 +119,14 @@ class HeatException(Exception):
raise exc_info[0], exc_info[1], exc_info[2]
def __str__(self):
return str(self.message)
return unicode(self.message).encode('UTF-8')
def __unicode__(self):
return unicode(self.message)
def __deepcopy__(self, memo):
return self.__class__(**self.kwargs)
class MissingCredentialError(HeatException):
msg_fmt = _("Missing required credential: %(required)s")

View File

@ -758,7 +758,7 @@ def log_exception(err, exc_info):
def translate_exception(exc, locale):
"""Translates all translatable elements of the given exception."""
exc.message = gettextutils.translate(str(exc), locale)
exc.message = gettextutils.translate(unicode(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
@ -767,7 +767,7 @@ def translate_exception(exc, locale):
# 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.explanation = unicode(exc)
exc.detail = ''
else:
exc.explanation = \