diff options
| author | Jenkins <jenkins@review.openstack.org> | 2013-08-15 21:15:59 +0000 |
|---|---|---|
| committer | Gerrit Code Review <review@openstack.org> | 2013-08-15 21:15:59 +0000 |
| commit | 24adfab8e07a2c58637f6345ba5f2a9abdf0bf28 (patch) | |
| tree | 3b6abd93a195253b259d5d3d8399d1c5263b1736 /openstack | |
| parent | 0ee72789a81ec96460608c7c5aacc162f004b5bd (diff) | |
| parent | 17df920eeb2b4f14a02a5ed6a5566c82835a24e0 (diff) | |
| download | oslo-24adfab8e07a2c58637f6345ba5f2a9abdf0bf28.tar.gz oslo-24adfab8e07a2c58637f6345ba5f2a9abdf0bf28.tar.xz oslo-24adfab8e07a2c58637f6345ba5f2a9abdf0bf28.zip | |
Merge "Allow mapping _ to lazy gettext path"
Diffstat (limited to 'openstack')
| -rw-r--r-- | openstack/common/gettextutils.py | 18 |
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): |
