From fa133569a46d283c69abe3cc46b6f16f089530f5 Mon Sep 17 00:00:00 2001 From: "cbjchen@cn.ibm.com" Date: Sat, 25 Jan 2014 23:13:03 +0800 Subject: [PATCH] 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 --- bin/heat-api | 3 ++- bin/heat-api-cfn | 3 ++- bin/heat-api-cloudwatch | 3 ++- bin/heat-engine | 3 ++- heat/common/exception.py | 5 ++++- heat/common/wsgi.py | 4 ++-- 6 files changed, 14 insertions(+), 7 deletions(-) diff --git a/bin/heat-api b/bin/heat-api index 3f9eeeabd..d9f7495e2 100755 --- a/bin/heat-api +++ b/bin/heat-api @@ -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 diff --git a/bin/heat-api-cfn b/bin/heat-api-cfn index 03a14028b..54bdf637f 100755 --- a/bin/heat-api-cfn +++ b/bin/heat-api-cfn @@ -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 diff --git a/bin/heat-api-cloudwatch b/bin/heat-api-cloudwatch index 9100e878e..79feb70a9 100755 --- a/bin/heat-api-cloudwatch +++ b/bin/heat-api-cloudwatch @@ -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 diff --git a/bin/heat-engine b/bin/heat-engine index 6f05e167c..185d48ee1 100755 --- a/bin/heat-engine +++ b/bin/heat-engine @@ -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 diff --git a/heat/common/exception.py b/heat/common/exception.py index b196f6d53..6f2150fd4 100644 --- a/heat/common/exception.py +++ b/heat/common/exception.py @@ -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") diff --git a/heat/common/wsgi.py b/heat/common/wsgi.py index e98444f26..473831499 100644 --- a/heat/common/wsgi.py +++ b/heat/common/wsgi.py @@ -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 = \