diff options
Diffstat (limited to 'nova')
| -rw-r--r-- | nova/cmd/__init__.py | 4 | ||||
| -rw-r--r-- | nova/openstack/common/gettextutils.py | 23 |
2 files changed, 22 insertions, 5 deletions
diff --git a/nova/cmd/__init__.py b/nova/cmd/__init__.py index 9ee46ea44..7595cb6b7 100644 --- a/nova/cmd/__init__.py +++ b/nova/cmd/__init__.py @@ -33,5 +33,5 @@ import eventlet eventlet.monkey_patch(os=False) -import gettext -gettext.install('nova', unicode=1) +from nova.openstack.common import gettextutils +gettextutils.install('nova') diff --git a/nova/openstack/common/gettextutils.py b/nova/openstack/common/gettextutils.py index b9993b491..2d2e94a7c 100644 --- a/nova/openstack/common/gettextutils.py +++ b/nova/openstack/common/gettextutils.py @@ -24,10 +24,27 @@ Usual usage in an openstack.common module: """ import gettext +import os - -t = gettext.translation('nova', 'locale', fallback=True) +_localedir = os.environ.get('nova'.upper() + '_LOCALEDIR') +_t = gettext.translation('nova', 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) |
