From 61533bbe247af2a3f5d7fbc28b25a29ddd86e4c3 Mon Sep 17 00:00:00 2001 From: Ghe Rivero Date: Mon, 7 Jul 2014 10:05:25 +0000 Subject: [PATCH] oslo.i18n migration Switch ironic to use oslo.i18n. A new i18n module has been added under ironic with translation globals and imports the necessary functions from oslo.i18n. gettextutils module is still needed in the nova ironic driver. Change-Id: I682228e158132c628166e4d1e334c4003249d112 --- ironic/api/app.wsgi | 5 +++-- ironic/cmd/__init__.py | 5 +++-- ironic/common/exception.py | 2 +- ironic/common/i18n.py | 31 +++++++++++++++++++++++++++++++ ironic/common/policy.py | 2 +- requirements.txt | 1 + tox.ini | 2 +- 7 files changed, 41 insertions(+), 7 deletions(-) create mode 100644 ironic/common/i18n.py diff --git a/ironic/api/app.wsgi b/ironic/api/app.wsgi index 20f3a186b2..60b2a1fb8e 100644 --- a/ironic/api/app.wsgi +++ b/ironic/api/app.wsgi @@ -18,9 +18,10 @@ Use this file for deploying the API service under Apache2 mod_wsgi. from ironic.api import app from ironic.common import service -from ironic.openstack.common import gettextutils -gettextutils.install('ironic') +from oslo import i18n + +i18n.install('ironic') service.prepare_service([]) diff --git a/ironic/cmd/__init__.py b/ironic/cmd/__init__.py index 8513749e8d..ce9194ba54 100644 --- a/ironic/cmd/__init__.py +++ b/ironic/cmd/__init__.py @@ -13,5 +13,6 @@ # License for the specific language governing permissions and limitations # under the License. -from ironic.openstack.common import gettextutils -gettextutils.install('ironic') +from oslo import i18n + +i18n.install('ironic') diff --git a/ironic/common/exception.py b/ironic/common/exception.py index f0318f0287..e9e11f6d39 100644 --- a/ironic/common/exception.py +++ b/ironic/common/exception.py @@ -25,7 +25,7 @@ SHOULD include dedicated exception logging. from oslo.config import cfg import six -from ironic.openstack.common.gettextutils import _ +from ironic.common.i18n import _ from ironic.openstack.common import log as logging diff --git a/ironic/common/i18n.py b/ironic/common/i18n.py new file mode 100644 index 0000000000..b6ab4f4e50 --- /dev/null +++ b/ironic/common/i18n.py @@ -0,0 +1,31 @@ +# Copyright (c) 2014 Hewlett-Packard Development Company, L.P. +# 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 import i18n # noqa + +_translators = i18n.TranslatorFactory(domain='ironic') + +# 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/ironic/common/policy.py b/ironic/common/policy.py index 66e5a1d330..88bc97b64d 100644 --- a/ironic/common/policy.py +++ b/ironic/common/policy.py @@ -20,8 +20,8 @@ import os.path from oslo.config import cfg from ironic.common import exception +from ironic.common.i18n import _ from ironic.common import utils -from ironic.openstack.common.gettextutils import _ from ironic.openstack.common import policy diff --git a/requirements.txt b/requirements.txt index 2bfe50e9fc..a98eba9485 100644 --- a/requirements.txt +++ b/requirements.txt @@ -22,6 +22,7 @@ pysendfile==2.0.0 websockify>=0.5.1,<0.6 oslo.config>=1.2.1 oslo.rootwrap +oslo.i18n>=0.1.0 # Apache-2.0 pecan>=0.4.5 six>=1.7.0 jsonpatch>=1.1 diff --git a/tox.ini b/tox.ini index e46c5ba387..f8e66abda4 100644 --- a/tox.ini +++ b/tox.ini @@ -48,4 +48,4 @@ exclude = .venv,.git,.tox,dist,doc,*openstack/common*,*lib/python*,*egg,build,t [hacking] import_exceptions = ironic.openstack.common.gettextutils._, ironic.openstack.common.gettextutils._LI, ironic.openstack.common.gettextutils._LW,ironic.openstack.common.gettextutils._LE, - ironic.openstack.common.gettextutils._LC, testtools.matchers + ironic.openstack.common.gettextutils._LC, testtools.matchers, ironic.common.i18n._