NameError: global name '_' not found in most bins

Bug #694844 reported by clayg
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
OpenStack Object Storage (swift)
Fix Released
Low
clayg

Bug Description

$ swift-proxy-server
Usage: swift-proxy-server CONFIG [options]

Traceback (most recent call last):
  File "/usr/local/bin/swift-proxy-server", line 7, in <module>
    execfile(__file__)
  File "/home/clayg/local/bin/swift-proxy-server", line 21, in <module>
    conf_file, options = parse_options()
  File "/home/clayg/local/swift/common/utils.py", line 465, in parse_options
    print _("Error: missing config file argument")
NameError: global name '_' is not defined

Related branches

Revision history for this message
Jay Pipes (jaypipes) wrote :

When i18n'ing, all endpoints (bin/*, test runners, etc) must have the following:

import gettext

gettext.install('swift')

*Before* any imports that may use the _() method installed through gettext.

Hope this helps!
-jay

Revision history for this message
Mike Barton (redbo) wrote : Re: [Bug 694844] Re: NameError: global name '_' not found in most bins

I originally didn't do it that way because it's being kind of a bad
Python citizen.

But I'm fine with it since nobody should really be using us as a
library for another app, and we're already doing worse things like
monkey patching shit when utils is imported.

Revision history for this message
Jay Pipes (jaypipes) wrote :

Yes, I realize it's being a bad Python citizen, but it's the standard way of working with gettext in Python, and is what is documented in the Python manual... The other way to go about doing it is the Django way, which essentially duplicates the entire gettext library so that _ isn't installed into builtins but instead can be imported as a symbol (from django.translation import ugettext as _).

The latter is a heck of a lot more coding...

Changed in swift:
status: New → Fix Committed
assignee: nobody → clayg (clay-gerrard)
Chuck Thier (cthier)
Changed in swift:
milestone: none → 1.2.0
Chuck Thier (cthier)
Changed in swift:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.