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
This commit is contained in:
Mark McLoughlin 2013-05-08 13:52:51 +01:00 committed by Zhiteng Huang
parent 7cfb0388ff
commit 68f28d257c
9 changed files with 19 additions and 19 deletions

@ -30,7 +30,6 @@ continue attempting to launch the rest of the services.
import eventlet import eventlet
eventlet.monkey_patch() eventlet.monkey_patch()
import gettext
import os import os
import sys 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")): if os.path.exists(os.path.join(possible_topdir, "cinder", "__init__.py")):
sys.path.insert(0, possible_topdir) 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 import flags
from cinder.openstack.common import log as logging from cinder.openstack.common import log as logging

@ -26,7 +26,6 @@
import eventlet import eventlet
eventlet.monkey_patch() eventlet.monkey_patch()
import gettext
import os import os
import sys 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")): if os.path.exists(os.path.join(possible_topdir, "cinder", "__init__.py")):
sys.path.insert(0, possible_topdir) 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 import flags
from cinder.openstack.common import log as logging from cinder.openstack.common import log as logging

@ -17,7 +17,6 @@
"""Starter script for Cinder Volume Backup.""" """Starter script for Cinder Volume Backup."""
import gettext
import os import os
import sys 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')): if os.path.exists(os.path.join(possible_topdir, 'cinder', '__init__.py')):
sys.path.insert(0, possible_topdir) 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 import flags
from cinder.openstack.common import log as logging from cinder.openstack.common import log as logging

@ -24,7 +24,6 @@
""" """
import datetime import datetime
import gettext
import os import os
import sys import sys
import time 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')): if os.path.exists(os.path.join(POSSIBLE_TOPDIR, 'cinder', '__init__.py')):
sys.path.insert(0, POSSIBLE_TOPDIR) 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 from oslo.config import cfg

@ -54,7 +54,6 @@
CLI interface for cinder management. CLI interface for cinder management.
""" """
import gettext
import os import os
import sys import sys
import uuid 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')): if os.path.exists(os.path.join(POSSIBLE_TOPDIR, 'cinder', '__init__.py')):
sys.path.insert(0, POSSIBLE_TOPDIR) 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 from oslo.config import cfg

@ -22,7 +22,6 @@
import eventlet import eventlet
eventlet.monkey_patch() eventlet.monkey_patch()
import gettext
import os import os
import sys 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')): if os.path.exists(os.path.join(possible_topdir, 'cinder', '__init__.py')):
sys.path.insert(0, possible_topdir) 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 import flags
from cinder.openstack.common import log as logging from cinder.openstack.common import log as logging

@ -22,7 +22,6 @@
import eventlet import eventlet
eventlet.monkey_patch() eventlet.monkey_patch()
import gettext
import os import os
import sys 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')): if os.path.exists(os.path.join(possible_topdir, 'cinder', '__init__.py')):
sys.path.insert(0, possible_topdir) 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 import flags
from cinder.openstack.common import log as logging from cinder.openstack.common import log as logging

@ -34,7 +34,6 @@
Jan 1 through Dec 31 of the previous year. Jan 1 through Dec 31 of the previous year.
""" """
import gettext
import os import os
import sys import sys
import traceback 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')): if os.path.exists(os.path.join(POSSIBLE_TOPDIR, 'cinder', '__init__.py')):
sys.path.insert(0, POSSIBLE_TOPDIR) 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 context
from cinder import db from cinder import db
from cinder import flags from cinder import flags

@ -24,8 +24,8 @@ in cinder/tests/test_localization.py.
The ``_()`` function is brought into the global scope by doing:: The ``_()`` function is brought into the global scope by doing::
import gettext from cinder.openstack.common import gettextutils
gettext.install("cinder", unicode=1) gettextutils.install("cinder")
These lines are needed in any toplevel script before any cinder modules are 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:: imported. If this code is missing, it may result in an error that looks like::