summaryrefslogtreecommitdiffstats
path: root/openstack/common
diff options
context:
space:
mode:
authorMatt Odden <mrodden@us.ibm.com>2013-08-07 09:09:07 +0000
committerMatt Odden <mrodden@us.ibm.com>2013-08-14 05:55:49 +0000
commit17df920eeb2b4f14a02a5ed6a5566c82835a24e0 (patch)
tree6031fc599369afcd11abf79294acf397305b7016 /openstack/common
parent4c02e0a1181c669bcf19571edbe0c6d58cbc5a4f (diff)
downloadoslo-17df920eeb2b4f14a02a5ed6a5566c82835a24e0.tar.gz
oslo-17df920eeb2b4f14a02a5ed6a5566c82835a24e0.tar.xz
oslo-17df920eeb2b4f14a02a5ed6a5566c82835a24e0.zip
Allow mapping _ to lazy gettext path
Since nova has switched from using gettext.install for importing the _ function to explicitly importing the _ function from gettextutils, we need to be able to enable our deferred translation code path on the gettextutils._ function. Change-Id: I7fec00810ea57c985e1f43c644913a9980b35655
Diffstat (limited to 'openstack/common')
-rw-r--r--openstack/common/gettextutils.py18
1 files changed, 17 insertions, 1 deletions
diff --git a/openstack/common/gettextutils.py b/openstack/common/gettextutils.py
index bbf8fe9..321fdd0 100644
--- a/openstack/common/gettextutils.py
+++ b/openstack/common/gettextutils.py
@@ -38,10 +38,26 @@ _localedir = os.environ.get('oslo'.upper() + '_LOCALEDIR')
_t = gettext.translation('oslo', localedir=_localedir, fallback=True)
_AVAILABLE_LANGUAGES = []
+USE_LAZY = False
+
+
+def enable_lazy():
+ """Convenience function for configuring _() to use lazy gettext
+
+ Call this at the start of execution to enable the gettextutils._
+ function to use lazy gettext functionality. This is useful if
+ your project is importing _ directly instead of using the
+ gettextutils.install() way of importing the _ function.
+ """
+ global USE_LAZY
+ USE_LAZY = True
def _(msg):
- return _t.ugettext(msg)
+ if USE_LAZY:
+ return Message(msg, 'oslo')
+ else:
+ return _t.ugettext(msg)
def install(domain, lazy=False):