diff --git a/quantumclient/__init__.py b/quantumclient/__init__.py index 5558fdb97..034d66eaf 100644 --- a/quantumclient/__init__.py +++ b/quantumclient/__init__.py @@ -15,9 +15,3 @@ # License for the specific language governing permissions and limitations # under the License. # @author: Tyler Smith, Cisco Systems - -import gettext - - -# gettext must be initialized before any quantumclient imports -gettext.install('quantumclient', unicode=1) diff --git a/quantumclient/common/__init__.py b/quantumclient/common/__init__.py index 7e695ff08..1415c50a3 100644 --- a/quantumclient/common/__init__.py +++ b/quantumclient/common/__init__.py @@ -14,3 +14,11 @@ # License for the specific language governing permissions and limitations # under the License. # @author: Somik Behera, Nicira Networks, Inc. + +import gettext + +t = gettext.translation('quantumclient', fallback=True) + + +def _(msg): + return t.ugettext(msg) diff --git a/quantumclient/common/exceptions.py b/quantumclient/common/exceptions.py index 734a49894..22ac67a49 100644 --- a/quantumclient/common/exceptions.py +++ b/quantumclient/common/exceptions.py @@ -15,6 +15,8 @@ # License for the specific language governing permissions and limitations # under the License. +from quantumclient.common import _ + """ Quantum base exception handling. """ diff --git a/quantumclient/shell.py b/quantumclient/shell.py index 3b8ae5c84..21f64cf8f 100644 --- a/quantumclient/shell.py +++ b/quantumclient/shell.py @@ -33,7 +33,6 @@ from quantumclient.common import exceptions as exc from quantumclient.common import utils -gettext.install('quantum', unicode=1) VERSION = '2.0' QUANTUM_API_VERSION = '2.0' @@ -564,6 +563,7 @@ class QuantumShell(App): def main(argv=sys.argv[1:]): + gettext.install('quantumclient', unicode=1) try: return QuantumShell(QUANTUM_API_VERSION).run(argv) except exc.QuantumClientException: diff --git a/quantumclient/tests/unit/__init__.py b/quantumclient/tests/unit/__init__.py index e69de29bb..353303fb4 100644 --- a/quantumclient/tests/unit/__init__.py +++ b/quantumclient/tests/unit/__init__.py @@ -0,0 +1,22 @@ +# Copyright 2013 OpenStack LLC. +# 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. +# +# vim: tabstop=4 shiftwidth=4 softtabstop=4 + +import gettext + +# Because we installed '_' for quantum cli in shell.py, this help unittest +# have definition of '_' +gettext.install('quantumclient', unicode=1) diff --git a/quantumclient/v2_0/client.py b/quantumclient/v2_0/client.py index 305ea1e5f..9c045fc92 100644 --- a/quantumclient/v2_0/client.py +++ b/quantumclient/v2_0/client.py @@ -21,6 +21,7 @@ import time import urllib from quantumclient.client import HTTPClient +from quantumclient.common import _ from quantumclient.common import exceptions from quantumclient.common.serializer import Serializer