Sync gettextutils from oslo-incubator

Partially implements bp user-locale-api

Change-Id: Ie9dd8732800bdbe1551e02853c1ffdeb88917d50
This commit is contained in:
Brad Pokorny 2013-08-16 21:59:20 +00:00
parent b59a03109c
commit 4ecfa8b0a4

View File

@ -38,10 +38,26 @@ _localedir = os.environ.get('ceilometer'.upper() + '_LOCALEDIR')
_t = gettext.translation('ceilometer', 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, 'ceilometer')
else:
return _t.ugettext(msg)
def install(domain, lazy=False):
@ -137,7 +153,7 @@ class Message(UserString.UserString, object):
# look for %(blah) fields in string;
# ignore %% and deal with the
# case where % is first character on the line
keys = re.findall('(?:[^%]|^)%\((\w*)\)[a-z]', full_msg)
keys = re.findall('(?:[^%]|^)?%\((\w*)\)[a-z]', full_msg)
# if we don't find any %(blah) blocks but have a %s
if not keys and re.findall('(?:[^%]|^)%[a-z]', full_msg):