Switch over oslo.i18n
oslo.i18n has recently been released. This patch switches glance over oslo.i18n. As per oslo.i18n's instructions, a new i18n module has been added under glance. This module defines the translation globals and imports the necessary functions from oslo.i18n. The patch doesn't change the way Glance does translation, this means that a `_` function is still being injected to the builtins. Note that the gettextutils module is still a required module from oslo-inc because there are oslo-inc modules that depend on the old gettextutils module. Change-Id: Ieb83681e35f72a5a4ecd849bb76af7f78d9fdcb0
This commit is contained in:
parent
3e174591e3
commit
c300e1c259
@ -13,5 +13,7 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from glance.openstack.common import gettextutils
|
||||
gettextutils.install('glance', lazy=True)
|
||||
from glance import i18n
|
||||
|
||||
i18n.enable_lazy()
|
||||
i18n.install('glance')
|
||||
|
@ -44,7 +44,7 @@ from webob import multidict
|
||||
|
||||
from glance.common import exception
|
||||
from glance.common import utils
|
||||
from glance.openstack.common import gettextutils
|
||||
from glance import i18n
|
||||
from glance.openstack.common import jsonutils
|
||||
import glance.openstack.common.log as logging
|
||||
from glance.openstack.common import processutils
|
||||
@ -526,7 +526,7 @@ class Request(webob.Request):
|
||||
"""
|
||||
if not self.accept_language:
|
||||
return None
|
||||
langs = gettextutils.get_available_languages('glance')
|
||||
langs = i18n.get_available_languages('glance')
|
||||
return self.accept_language.best_match(langs)
|
||||
|
||||
|
||||
@ -596,10 +596,10 @@ def translate_exception(req, e):
|
||||
locale = req.best_match_language()
|
||||
|
||||
if isinstance(e, webob.exc.HTTPError):
|
||||
e.explanation = gettextutils.translate(e.explanation, locale)
|
||||
e.detail = gettextutils.translate(e.detail, locale)
|
||||
e.explanation = i18n.translate(e.explanation, locale)
|
||||
e.detail = i18n.translate(e.detail, locale)
|
||||
if getattr(e, 'body_template', None):
|
||||
e.body_template = gettextutils.translate(e.body_template, locale)
|
||||
e.body_template = i18n.translate(e.body_template, locale)
|
||||
return e
|
||||
|
||||
|
||||
|
31
glance/i18n.py
Normal file
31
glance/i18n.py
Normal file
@ -0,0 +1,31 @@
|
||||
# Copyright 2014 Red Hat, Inc.
|
||||
# All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from oslo.i18n import * # noqa
|
||||
|
||||
_translators = TranslatorFactory(domain='glance')
|
||||
|
||||
# The primary translation function using the well-known name "_"
|
||||
_ = _translators.primary
|
||||
|
||||
# Translators for log levels.
|
||||
#
|
||||
# The abbreviated names are meant to reflect the usual use of a short
|
||||
# name like '_'. The "L" is for "log" and the other letter comes from
|
||||
# the level.
|
||||
_LI = _translators.log_info
|
||||
_LW = _translators.log_warning
|
||||
_LE = _translators.log_error
|
||||
_LC = _translators.log_critical
|
@ -28,8 +28,8 @@ from six import text_type
|
||||
|
||||
from glance.common import exception
|
||||
from glance.common import utils
|
||||
from glance import i18n
|
||||
from glance.openstack.common import excutils
|
||||
from glance.openstack.common import gettextutils
|
||||
import glance.openstack.common.log as logging
|
||||
from glance.openstack.common import units
|
||||
import glance.store.base
|
||||
@ -49,7 +49,7 @@ DEFAULT_CHUNKSIZE = 8 # in MiB
|
||||
DEFAULT_SNAPNAME = 'snap'
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
_LI = gettextutils._LI
|
||||
_LI = i18n._LI
|
||||
|
||||
rbd_opts = [
|
||||
cfg.IntOpt('rbd_store_chunk_size', default=DEFAULT_CHUNKSIZE,
|
||||
|
@ -29,7 +29,7 @@ import six.moves.urllib.parse as urlparse
|
||||
|
||||
from glance.common import exception
|
||||
from glance.common import utils
|
||||
from glance.openstack.common import gettextutils
|
||||
from glance import i18n
|
||||
import glance.openstack.common.log as logging
|
||||
from glance.openstack.common import units
|
||||
import glance.store
|
||||
@ -37,8 +37,8 @@ import glance.store.base
|
||||
import glance.store.location
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
_LE = gettextutils._LE
|
||||
_LI = gettextutils._LI
|
||||
_LE = i18n._LE
|
||||
_LI = i18n._LI
|
||||
|
||||
DEFAULT_LARGE_OBJECT_SIZE = 100 # 100M
|
||||
DEFAULT_LARGE_OBJECT_CHUNK_SIZE = 10 # 10M
|
||||
|
@ -28,8 +28,8 @@ import urllib
|
||||
from glance.common import auth
|
||||
from glance.common import exception
|
||||
from glance.common import swift_store_utils
|
||||
from glance import i18n
|
||||
from glance.openstack.common import excutils
|
||||
from glance.openstack.common import gettextutils
|
||||
import glance.openstack.common.log as logging
|
||||
import glance.store
|
||||
import glance.store.base
|
||||
@ -41,7 +41,7 @@ except ImportError:
|
||||
pass
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
_LI = gettextutils._LI
|
||||
_LI = i18n._LI
|
||||
|
||||
DEFAULT_CONTAINER = 'glance'
|
||||
DEFAULT_LARGE_OBJECT_SIZE = 5 * 1024 # 5GB
|
||||
|
@ -28,7 +28,7 @@ import webob
|
||||
from glance.common import exception
|
||||
from glance.common import utils
|
||||
from glance.common import wsgi
|
||||
from glance.openstack.common import gettextutils
|
||||
from glance import i18n
|
||||
from glance.tests import utils as test_utils
|
||||
|
||||
|
||||
@ -266,7 +266,7 @@ class ResourceTest(test_utils.BaseTestCase):
|
||||
self.assertEqual(message_es, str(e))
|
||||
|
||||
@mock.patch.object(webob.acceptparse.AcceptLanguage, 'best_match')
|
||||
@mock.patch.object(gettextutils, 'translate')
|
||||
@mock.patch.object(i18n, 'translate')
|
||||
def test_translate_exception(self, mock_translate, mock_best_match):
|
||||
|
||||
mock_translate.return_value = 'No Encontrado'
|
||||
|
@ -43,4 +43,5 @@ pyOpenSSL>=0.11
|
||||
# Required by openstack.common libraries
|
||||
six>=1.7.0
|
||||
|
||||
oslo.i18n>=0.1.0
|
||||
oslo.messaging>=1.3.0
|
||||
|
Loading…
Reference in New Issue
Block a user