diff --git a/bin/keystone-all b/bin/keystone-all index b38e552b50..7e6711b5df 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 b440ad15a6..89ada5bded 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 ae3716d9a2..e2f5055a75 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 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 d52309e62a..55ba338725 100644 --- a/keystone/openstack/common/gettextutils.py +++ b/keystone/openstack/common/gettextutils.py @@ -20,14 +20,31 @@ 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 82ab99a6b5..3cfbd01ccd 100644 --- a/keystone/test.py +++ b/keystone/test.py @@ -22,6 +22,7 @@ import sys import time +import gettext import mox import nose.exc from paste import deploy @@ -47,6 +48,8 @@ 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')