diff options
author | Mark McLoughlin <markmc@redhat.com> | 2013-05-08 12:07:07 +0100 |
---|---|---|
committer | Mark McLoughlin <markmc@redhat.com> | 2013-05-29 10:40:00 +0100 |
commit | 7ce56d5f45f7112f0b25061473e64145fc840c98 (patch) | |
tree | fd0860917372258411ecdd3f512dda1b1111e8da | |
parent | 2879d42de12cfb5a141197debbf7eaa53cd6750f (diff) | |
download | keystone-7ce56d5f45f7112f0b25061473e64145fc840c98.tar.gz keystone-7ce56d5f45f7112f0b25061473e64145fc840c98.tar.xz keystone-7ce56d5f45f7112f0b25061473e64145fc840c98.zip |
Add KEYSTONE_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.
A few things to note:
- the gettext.install() call is moved from common.config to the
toplevel scripts to fix cases (e.g. the legacy auth_token middleware)
where keystone code might be imported by a program who's default
translation domain is not 'keystone'.
- we add a gettext.install() call in keystone.test so that tests have
the _() builtin installed.
Change-Id: I86562b3a65d371673bb21f7179eecc7602bc0775
-rwxr-xr-x | bin/keystone-all | 3 | ||||
-rwxr-xr-x | bin/keystone-manage | 4 | ||||
-rw-r--r-- | keystone/common/config.py | 3 | ||||
-rw-r--r-- | keystone/openstack/common/gettextutils.py | 25 | ||||
-rw-r--r-- | keystone/test.py | 3 |
5 files changed, 30 insertions, 8 deletions
diff --git a/bin/keystone-all b/bin/keystone-all index b38e552b..7e6711b5 100755 --- a/bin/keystone-all +++ b/bin/keystone-all @@ -24,6 +24,7 @@ import pbr.version from keystone.common import utils from keystone.common import wsgi_server from keystone import config +from keystone.openstack.common import gettextutils from keystone.openstack.common import importutils @@ -70,6 +71,8 @@ def serve(*servers): if __name__ == '__main__': + gettextutils.install('keystone') + dev_conf = os.path.join(possible_topdir, 'etc', 'keystone.conf') diff --git a/bin/keystone-manage b/bin/keystone-manage index b440ad15..89ada5bd 100755 --- a/bin/keystone-manage +++ b/bin/keystone-manage @@ -13,11 +13,13 @@ if os.path.exists(os.path.join(possible_topdir, '__init__.py')): sys.path.insert(0, possible_topdir) - from keystone import cli +from keystone.openstack.common import gettextutils if __name__ == '__main__': + gettextutils.install('keystone') + dev_conf = os.path.join(possible_topdir, 'etc', 'keystone.conf') diff --git a/keystone/common/config.py b/keystone/common/config.py index ae3716d9..e2f5055a 100644 --- a/keystone/common/config.py +++ b/keystone/common/config.py @@ -14,7 +14,6 @@ # License for the specific language governing permissions and limitations # under the License. -import gettext import os import sys @@ -23,8 +22,6 @@ from oslo.config import cfg from keystone.common import logging -gettext.install('keystone', unicode=1) - _DEFAULT_LOG_FORMAT = "%(asctime)s %(levelname)8s [%(name)s] %(message)s" _DEFAULT_LOG_DATE_FORMAT = "%Y-%m-%d %H:%M:%S" _DEFAULT_AUTH_METHODS = ['password', 'token'] diff --git a/keystone/openstack/common/gettextutils.py b/keystone/openstack/common/gettextutils.py index d52309e6..55ba3387 100644 --- a/keystone/openstack/common/gettextutils.py +++ b/keystone/openstack/common/gettextutils.py @@ -20,14 +20,31 @@ gettext for openstack-common modules. Usual usage in an openstack.common module: - from nova.openstack.common.gettextutils import _ + from keystone.openstack.common.gettextutils import _ """ import gettext +import os - -t = gettext.translation('openstack-common', 'locale', fallback=True) +_localedir = os.environ.get('keystone'.upper() + '_LOCALEDIR') +_t = gettext.translation('keystone', localedir=_localedir, fallback=True) def _(msg): - return t.ugettext(msg) + return _t.ugettext(msg) + + +def install(domain): + """Install a _() function using the given translation domain. + + Given a translation domain, install a _() function using gettext's + install() function. + + The main difference from gettext.install() is that we allow + overriding the default localedir (e.g. /usr/share/locale) using + a translation-domain-specific environment variable (e.g. + NOVA_LOCALEDIR). + """ + gettext.install(domain, + localedir=os.environ.get(domain.upper() + '_LOCALEDIR'), + unicode=True) diff --git a/keystone/test.py b/keystone/test.py index 82ab99a6..3cfbd01c 100644 --- a/keystone/test.py +++ b/keystone/test.py @@ -22,6 +22,7 @@ import subprocess import sys import time +import gettext import mox import nose.exc from paste import deploy @@ -47,6 +48,8 @@ from keystone import trust wsgi_server.monkey_patch_eventlet() +gettext.install('keystone', unicode=1) + LOG = logging.getLogger(__name__) ROOTDIR = os.path.dirname(os.path.abspath(os.curdir)) VENDOR = os.path.join(ROOTDIR, 'vendor') |