diff --git a/glance/cmd/__init__.py b/glance/cmd/__init__.py index c74be858f1..a02646be22 100644 --- a/glance/cmd/__init__.py +++ b/glance/cmd/__init__.py @@ -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') diff --git a/glance/common/wsgi.py b/glance/common/wsgi.py index 75895428b5..d335d87f6f 100644 --- a/glance/common/wsgi.py +++ b/glance/common/wsgi.py @@ -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 diff --git a/glance/i18n.py b/glance/i18n.py new file mode 100644 index 0000000000..d17b588252 --- /dev/null +++ b/glance/i18n.py @@ -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 diff --git a/glance/store/rbd.py b/glance/store/rbd.py index af073d1e83..b67fdb523d 100644 --- a/glance/store/rbd.py +++ b/glance/store/rbd.py @@ -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, diff --git a/glance/store/s3.py b/glance/store/s3.py index b259394467..72ac0251ee 100644 --- a/glance/store/s3.py +++ b/glance/store/s3.py @@ -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 diff --git a/glance/store/swift.py b/glance/store/swift.py index 00aab2bb20..a6c1e1b3aa 100644 --- a/glance/store/swift.py +++ b/glance/store/swift.py @@ -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 diff --git a/glance/tests/unit/common/test_wsgi.py b/glance/tests/unit/common/test_wsgi.py index ce953c77f2..2ff867eabf 100644 --- a/glance/tests/unit/common/test_wsgi.py +++ b/glance/tests/unit/common/test_wsgi.py @@ -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' diff --git a/requirements.txt b/requirements.txt index da13b0f2d7..0130f904bc 100644 --- a/requirements.txt +++ b/requirements.txt @@ -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