Skip to content

Commit

Permalink
Re-enable lazy translation
Browse files Browse the repository at this point in the history
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: I4be508858547029d454412746609fd380af415c1
  • Loading branch information
Ethan Lynn committed May 27, 2014
1 parent 3407a69 commit f864a0c
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 6 deletions.
3 changes: 2 additions & 1 deletion bin/heat-api
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ from heat.common import wsgi
from heat.openstack.common import gettextutils
from heat.openstack.common import log as logging

gettextutils.install('heat', lazy=False)
gettextutils.enable_lazy()
gettextutils.install('heat', lazy=True)

LOG = logging.getLogger('heat.api')

Expand Down
3 changes: 2 additions & 1 deletion bin/heat-api-cfn
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ from heat.common import wsgi
from heat.openstack.common import gettextutils
from heat.openstack.common import log as logging

gettextutils.install('heat', lazy=False)
gettextutils.enable_lazy()
gettextutils.install('heat', lazy=True)

LOG = logging.getLogger('heat.api.cfn')

Expand Down
3 changes: 2 additions & 1 deletion bin/heat-api-cloudwatch
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ from heat.common import wsgi
from heat.openstack.common import gettextutils
from heat.openstack.common import log as logging

gettextutils.install('heat', lazy=False)
gettextutils.enable_lazy()
gettextutils.install('heat', lazy=True)

LOG = logging.getLogger('heat.api.cloudwatch')

Expand Down
4 changes: 2 additions & 2 deletions bin/heat-engine
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ POSSIBLE_TOPDIR = os.path.normpath(os.path.join(os.path.abspath(sys.argv[0]),
if os.path.exists(os.path.join(POSSIBLE_TOPDIR, 'heat', '__init__.py')):
sys.path.insert(0, POSSIBLE_TOPDIR)


from oslo.config import cfg

from heat.common import notify
Expand All @@ -41,7 +40,8 @@ from heat.openstack.common import log as logging
from heat.openstack.common import service
from heat.rpc import api as rpc_api

gettextutils.install('heat', lazy=False)
gettextutils.enable_lazy()
gettextutils.install('heat', lazy=True)

LOG = logging.getLogger('heat.engine')

Expand Down
3 changes: 3 additions & 0 deletions heat/api/middleware/fault.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,9 @@ def _error(self, ex):
msg_trace = traceback.format_exc()
message = full_message

if isinstance(ex, exception.HeatException):
message = ex.message

if cfg.CONF.debug and not trace:
trace = msg_trace

Expand Down
6 changes: 5 additions & 1 deletion heat/common/wsgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -719,7 +719,11 @@ def log_exception(err, exc_info):

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, exception.HeatException):
exc.message = gettextutils.translate(exc.message, locale)
else:
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
Expand Down

0 comments on commit f864a0c

Please sign in to comment.