From 7ce56d5f45f7112f0b25061473e64145fc840c98 Mon Sep 17 00:00:00 2001 From: Mark McLoughlin Date: Wed, 8 May 2013 12:07:07 +0100 Subject: 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 --- keystone/openstack/common/gettextutils.py | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) (limited to 'keystone/openstack') 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) -- cgit