Skip to content

Commit

Permalink
Add CINDER_LOCALEDIR env variable
Browse files Browse the repository at this point in the history
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
  • Loading branch information
markmc authored and zhiteng committed May 13, 2013
1 parent 7cfb038 commit 68f28d2
Show file tree
Hide file tree
Showing 9 changed files with 19 additions and 19 deletions.
4 changes: 2 additions & 2 deletions bin/cinder-all
Expand Up @@ -30,7 +30,6 @@ continue attempting to launch the rest of the services.
import eventlet
eventlet.monkey_patch()

import gettext
import os
import sys

Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions bin/cinder-api
Expand Up @@ -26,7 +26,6 @@
import eventlet
eventlet.monkey_patch()

import gettext
import os
import sys

Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions bin/cinder-backup
Expand Up @@ -17,7 +17,6 @@

"""Starter script for Cinder Volume Backup."""

import gettext
import os
import sys

Expand All @@ -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
Expand Down
5 changes: 2 additions & 3 deletions bin/cinder-clear-rabbit-queues
Expand Up @@ -24,7 +24,6 @@
"""

import datetime
import gettext
import os
import sys
import time
Expand All @@ -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

Expand Down
4 changes: 2 additions & 2 deletions bin/cinder-manage
Expand Up @@ -54,7 +54,6 @@
CLI interface for cinder management.
"""

import gettext
import os
import sys
import uuid
Expand All @@ -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

Expand Down
4 changes: 2 additions & 2 deletions bin/cinder-scheduler
Expand Up @@ -22,7 +22,6 @@
import eventlet
eventlet.monkey_patch()

import gettext
import os
import sys

Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions bin/cinder-volume
Expand Up @@ -22,7 +22,6 @@
import eventlet
eventlet.monkey_patch()

import gettext
import os
import sys

Expand All @@ -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
Expand Down
5 changes: 3 additions & 2 deletions bin/cinder-volume-usage-audit
Expand Up @@ -34,7 +34,6 @@
Jan 1 through Dec 31 of the previous year.
"""

import gettext
import os
import sys
import traceback
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions doc/source/devref/il8n.rst
Expand Up @@ -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::
Expand Down

0 comments on commit 68f28d2

Please sign in to comment.