summaryrefslogtreecommitdiffstats
path: root/bin/nova-api-metadata
diff options
context:
space:
mode:
authorMark McLoughlin <markmc@redhat.com>2013-04-01 00:53:25 +0100
committerMark McLoughlin <markmc@redhat.com>2013-04-01 13:44:47 -0400
commit9447e59b704701aad765f8ffa109843d9ffc88ae (patch)
tree93ca4734fc01feafea09fddba55b020e5d67da7c /bin/nova-api-metadata
parentc51321ce9703dacea710e2afeb0281cb16c25341 (diff)
downloadnova-9447e59b704701aad765f8ffa109843d9ffc88ae.tar.gz
nova-9447e59b704701aad765f8ffa109843d9ffc88ae.tar.xz
nova-9447e59b704701aad765f8ffa109843d9ffc88ae.zip
Remove gettext.install() from nova/__init__.py
The gettext.install() function installs a builtin _() function which translates a string in the translation domain supplied to the install() function. If gettext.install() is called multiple times, it's the last call to the function which wins and the last supplied translation domain which is used e.g. >>> import os >>> os.environ['LANG'] = 'ja.UTF-8' >>> import gettext >>> gettext.install('keystone', unicode=1, localedir='/opt/stack/keystone/keystone/locale') >>> print _('Invalid syslog facility') 無効な syslog ファシリティ >>> gettext.install('nova', unicode=1, localedir='/opt/stack/nova/nova/locale') >>> print _('Invalid syslog facility') Invalid syslog facility Usually this function is called early on in a toplevel script and we assume that no other code will call it and override the installed _(). However, in Nova, we have taken a shortcut to avoid having to call it explicitly from each script and instead call it from nova/__init__.py. This shortcut would be perfectly fine if we were absolutely sure that nova modules would never be imported from another program. It's probably quite incorrect for a program to use nova code (indeed, if we wanted to support this, Nova code shouldn't use the default _() function) but nevertheless there are some corner cases where it happens. For example, the keystoneclient auth_token middleware tries to import cfg from nova.openstack.common and this in turn causes gettext.install('nova') in other projects like glance or quantum. To avoid any doubt here, let's just rip out the shortcut and always call gettext.install() from the top-level script. Change-Id: If4125d6bcbde63df95de129ac5c83b4a6d6f130a
Diffstat (limited to 'bin/nova-api-metadata')
-rwxr-xr-xbin/nova-api-metadata2
1 files changed, 2 insertions, 0 deletions
diff --git a/bin/nova-api-metadata b/bin/nova-api-metadata
index e7cac260d..2005d6714 100755
--- a/bin/nova-api-metadata
+++ b/bin/nova-api-metadata
@@ -22,6 +22,7 @@
import eventlet
eventlet.monkey_patch(os=False)
+import gettext
import os
import sys
@@ -31,6 +32,7 @@ possible_topdir = os.path.normpath(os.path.join(os.path.abspath(
if os.path.exists(os.path.join(possible_topdir, "nova", "__init__.py")):
sys.path.insert(0, possible_topdir)
+gettext.install('nova', unicode=1)
from nova import config
from nova.openstack.common import log as logging