From 68f28d257c6e167bd819ae4ce385ae8c3602c8de Mon Sep 17 00:00:00 2001 From: Mark McLoughlin Date: Wed, 8 May 2013 13:52:51 +0100 Subject: [PATCH] Add CINDER_LOCALEDIR env variable Part of fixing bug #995287 Syncs these two commits from oslo-incubator: Support overriding oslo localedir too Add a gettextutils.install() helper function to get a new gettextutils.install() function which allows the default localedir to be overwritten via an environment variable. Note that gettextutils.install() must be called before any other cinder modules are imported since some modules attempt to translate strings at import time (e.g. in cinder.flags). This is broken and inefficient, but fixing it involves adding something like sphinx's l_() function and would be very invaisve. Change-Id: I86562b3a65d371673bb21f7179eecc7602bc0775 --- bin/cinder-all | 4 ++-- bin/cinder-api | 4 ++-- bin/cinder-backup | 4 ++-- bin/cinder-clear-rabbit-queues | 5 ++--- bin/cinder-manage | 4 ++-- bin/cinder-scheduler | 4 ++-- bin/cinder-volume | 4 ++-- bin/cinder-volume-usage-audit | 5 +++-- doc/source/devref/il8n.rst | 4 ++-- 9 files changed, 19 insertions(+), 19 deletions(-) diff --git a/bin/cinder-all b/bin/cinder-all index 6cfeedcce..9591d1574 100755 --- a/bin/cinder-all +++ b/bin/cinder-all @@ -30,7 +30,6 @@ continue attempting to launch the rest of the services. import eventlet eventlet.monkey_patch() -import gettext import os import sys @@ -40,7 +39,8 @@ possible_topdir = os.path.normpath(os.path.join(os.path.abspath( if os.path.exists(os.path.join(possible_topdir, "cinder", "__init__.py")): sys.path.insert(0, possible_topdir) -gettext.install('cinder', unicode=1) +from cinder.openstack.common import gettextutils +gettextutils.install('cinder') from cinder import flags from cinder.openstack.common import log as logging diff --git a/bin/cinder-api b/bin/cinder-api index 68c06782b..0f05b519c 100755 --- a/bin/cinder-api +++ b/bin/cinder-api @@ -26,7 +26,6 @@ import eventlet eventlet.monkey_patch() -import gettext import os import sys @@ -36,7 +35,8 @@ possible_topdir = os.path.normpath(os.path.join(os.path.abspath( if os.path.exists(os.path.join(possible_topdir, "cinder", "__init__.py")): sys.path.insert(0, possible_topdir) -gettext.install('cinder', unicode=1) +from cinder.openstack.common import gettextutils +gettextutils.install('cinder') from cinder import flags from cinder.openstack.common import log as logging diff --git a/bin/cinder-backup b/bin/cinder-backup index d0278a35a..71f83006a 100755 --- a/bin/cinder-backup +++ b/bin/cinder-backup @@ -17,7 +17,6 @@ """Starter script for Cinder Volume Backup.""" -import gettext import os import sys @@ -33,7 +32,8 @@ possible_topdir = os.path.normpath(os.path.join(os.path.abspath(sys.argv[0]), if os.path.exists(os.path.join(possible_topdir, 'cinder', '__init__.py')): sys.path.insert(0, possible_topdir) -gettext.install('cinder', unicode=1) +from cinder.openstack.common import gettextutils +gettextutils.install('cinder') from cinder import flags from cinder.openstack.common import log as logging diff --git a/bin/cinder-clear-rabbit-queues b/bin/cinder-clear-rabbit-queues index aa701706a..684a56578 100755 --- a/bin/cinder-clear-rabbit-queues +++ b/bin/cinder-clear-rabbit-queues @@ -24,7 +24,6 @@ """ import datetime -import gettext import os import sys import time @@ -37,8 +36,8 @@ POSSIBLE_TOPDIR = os.path.normpath(os.path.join(os.path.abspath(sys.argv[0]), if os.path.exists(os.path.join(POSSIBLE_TOPDIR, 'cinder', '__init__.py')): sys.path.insert(0, POSSIBLE_TOPDIR) -gettext.install('cinder', unicode=1) - +from cinder.openstack.common import gettextutils +gettextutils.install('cinder') from oslo.config import cfg diff --git a/bin/cinder-manage b/bin/cinder-manage index c358757d2..63f638fc4 100755 --- a/bin/cinder-manage +++ b/bin/cinder-manage @@ -54,7 +54,6 @@ CLI interface for cinder management. """ -import gettext import os import sys import uuid @@ -72,7 +71,8 @@ POSSIBLE_TOPDIR = os.path.normpath(os.path.join(os.path.abspath(sys.argv[0]), if os.path.exists(os.path.join(POSSIBLE_TOPDIR, 'cinder', '__init__.py')): sys.path.insert(0, POSSIBLE_TOPDIR) -gettext.install('cinder', unicode=1) +from cinder.openstack.common import gettextutils +gettextutils.install('cinder') from oslo.config import cfg diff --git a/bin/cinder-scheduler b/bin/cinder-scheduler index 33015b3ca..28edd8bbf 100755 --- a/bin/cinder-scheduler +++ b/bin/cinder-scheduler @@ -22,7 +22,6 @@ import eventlet eventlet.monkey_patch() -import gettext import os import sys @@ -34,7 +33,8 @@ possible_topdir = os.path.normpath(os.path.join(os.path.abspath(sys.argv[0]), if os.path.exists(os.path.join(possible_topdir, 'cinder', '__init__.py')): sys.path.insert(0, possible_topdir) -gettext.install('cinder', unicode=1) +from cinder.openstack.common import gettextutils +gettextutils.install('cinder') from cinder import flags from cinder.openstack.common import log as logging diff --git a/bin/cinder-volume b/bin/cinder-volume index bf144830b..9c36238d6 100755 --- a/bin/cinder-volume +++ b/bin/cinder-volume @@ -22,7 +22,6 @@ import eventlet eventlet.monkey_patch() -import gettext import os import sys @@ -34,7 +33,8 @@ possible_topdir = os.path.normpath(os.path.join(os.path.abspath(sys.argv[0]), if os.path.exists(os.path.join(possible_topdir, 'cinder', '__init__.py')): sys.path.insert(0, possible_topdir) -gettext.install('cinder', unicode=1) +from cinder.openstack.common import gettextutils +gettextutils.install('cinder') from cinder import flags from cinder.openstack.common import log as logging diff --git a/bin/cinder-volume-usage-audit b/bin/cinder-volume-usage-audit index 053de79a1..13ea447a9 100755 --- a/bin/cinder-volume-usage-audit +++ b/bin/cinder-volume-usage-audit @@ -34,7 +34,6 @@ Jan 1 through Dec 31 of the previous year. """ -import gettext import os import sys import traceback @@ -47,7 +46,9 @@ POSSIBLE_TOPDIR = os.path.normpath(os.path.join(os.path.abspath(sys.argv[0]), if os.path.exists(os.path.join(POSSIBLE_TOPDIR, 'cinder', '__init__.py')): sys.path.insert(0, POSSIBLE_TOPDIR) -gettext.install('cinder', unicode=1) +from cinder.openstack.common import gettextutils +gettextutils.install('cinder') + from cinder import context from cinder import db from cinder import flags diff --git a/doc/source/devref/il8n.rst b/doc/source/devref/il8n.rst index 7e53731d7..e175af477 100644 --- a/doc/source/devref/il8n.rst +++ b/doc/source/devref/il8n.rst @@ -24,8 +24,8 @@ in cinder/tests/test_localization.py. The ``_()`` function is brought into the global scope by doing:: - import gettext - gettext.install("cinder", unicode=1) + from cinder.openstack.common import gettextutils + gettextutils.install("cinder") These lines are needed in any toplevel script before any cinder modules are imported. If this code is missing, it may result in an error that looks like:: -- 2.45.2