summaryrefslogtreecommitdiffstats
path: root/openstack
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2013-04-04 14:39:30 +0000
committerGerrit Code Review <review@openstack.org>2013-04-04 14:39:30 +0000
commitaf25c217e9953e2e7b1c4e392a583e6fda653881 (patch)
tree7f79e4d336757f62550d4ae9575ce87c63e2768a /openstack
parent1d1e4cd6d94d1729c86ad52f5d32b630198fe9bf (diff)
parentd8b66c7c1bb28672402f2bf1e410a1ee8fc4bfb6 (diff)
downloadoslo-af25c217e9953e2e7b1c4e392a583e6fda653881.tar.gz
oslo-af25c217e9953e2e7b1c4e392a583e6fda653881.tar.xz
oslo-af25c217e9953e2e7b1c4e392a583e6fda653881.zip
Merge "Add a gettextutils.install() helper function"
Diffstat (limited to 'openstack')
-rw-r--r--openstack/common/gettextutils.py17
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)