diff options
| author | Mark McLoughlin <markmc@redhat.com> | 2013-04-01 02:01:00 +0100 |
|---|---|---|
| committer | Mark McLoughlin <markmc@redhat.com> | 2013-04-03 19:12:18 -0400 |
| commit | d8b66c7c1bb28672402f2bf1e410a1ee8fc4bfb6 (patch) | |
| tree | 7a8e1b2bc3aa5bb351cfe620615beb13789109ad /openstack/common | |
| parent | 05219b89b367b077a1e1f61a2767e71f7f44665a (diff) | |
| download | oslo-d8b66c7c1bb28672402f2bf1e410a1ee8fc4bfb6.tar.gz oslo-d8b66c7c1bb28672402f2bf1e410a1ee8fc4bfb6.tar.xz oslo-d8b66c7c1bb28672402f2bf1e410a1ee8fc4bfb6.zip | |
Add a gettextutils.install() helper function
Part of fixing bug #995287
Every top-level script in every project needs to call gettext.install()
so that a _() builtin function is installed and strings are translated
using the correct translation domain.
However, translations are always installed in the default localedir
(which is commonly '/usr/share/locale') and, in cases like devstack, may
be found in a project-specific localedir. To support such a use case we
should have project-specific environment variables for overriding the
default value of localedir - e.g. NOVA_LOCALEDIR.
Add a new gettextutils.install() helper method to make this as easy as
possible for projects to get right.
Change-Id: I6c8549c8ff00797c96f2dd4b0b5266d18d77aa19
Diffstat (limited to 'openstack/common')
| -rw-r--r-- | openstack/common/gettextutils.py | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/openstack/common/gettextutils.py b/openstack/common/gettextutils.py index 1e66538..efc6ec2 100644 --- a/openstack/common/gettextutils.py +++ b/openstack/common/gettextutils.py @@ -24,6 +24,7 @@ Usual usage in an openstack.common module: """ import gettext +import os t = gettext.translation('oslo', 'locale', fallback=True) @@ -31,3 +32,19 @@ t = gettext.translation('oslo', 'locale', fallback=True) def _(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) |
