Merge "Add NOVA_LOCALEDIR env variable"
This commit is contained in:
commit
9d52e07f60
|
@ -24,10 +24,14 @@ in nova/tests/test_localization.py.
|
|||
|
||||
The ``_()`` function is brought into the global scope by doing::
|
||||
|
||||
import gettext
|
||||
gettext.install("nova", unicode=1)
|
||||
from nova.openstack.common import gettextutils
|
||||
gettextutils.install('nova')
|
||||
|
||||
These lines are needed in any toplevel script before any nova modules are
|
||||
imported. If this code is missing, it may result in an error that looks like::
|
||||
|
||||
NameError: name '_' is not defined
|
||||
|
||||
The gettextutils.install() function also queries the NOVA_LOCALEDIR environment
|
||||
variable to allow overriding the default localedir with a specific custom
|
||||
location for Nova's message catalog.
|
||||
|
|
|
@ -33,5 +33,5 @@ import eventlet
|
|||
|
||||
eventlet.monkey_patch(os=False)
|
||||
|
||||
import gettext
|
||||
gettext.install('nova', unicode=1)
|
||||
from nova.openstack.common import gettextutils
|
||||
gettextutils.install('nova')
|
||||
|
|
|
@ -24,10 +24,27 @@ Usual usage in an openstack.common module:
|
|||
"""
|
||||
|
||||
import gettext
|
||||
import os
|
||||
|
||||
|
||||
t = gettext.translation('nova', 'locale', fallback=True)
|
||||
_localedir = os.environ.get('nova'.upper() + '_LOCALEDIR')
|
||||
_t = gettext.translation('nova', localedir=_localedir, fallback=True)
|
||||
|
||||
|
||||
def _(msg):
|
||||
return t.ugettext(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)
|
||||
|
|
Loading…
Reference in New Issue