--- a/src/client.py Thu Dec 18 13:08:47 2008 -0600
+++ b/src/client.py Thu Dec 18 11:15:47 2008 -0800
@@ -2068,7 +2068,7 @@
global __img
__img = img = image.Image()
- locale.setlocale(locale.LC_ALL, '')
+ misc.setlocale(locale.LC_ALL, "", error)
gettext.install("pkg", "/usr/share/locale")
try:
--- a/src/depot.py Thu Dec 18 13:08:47 2008 -0600
+++ b/src/depot.py Thu Dec 18 11:15:47 2008 -0800
@@ -94,7 +94,7 @@
import pkg.server.repository as repo
import pkg.server.repositoryconfig as rc
import pkg.search_errors as search_errors
-from pkg.misc import port_available, msg, emsg
+from pkg.misc import port_available, msg, emsg, setlocale
class LogSink(object):
"""This is a dummy object that we can use to discard log entries
@@ -151,7 +151,7 @@
if __name__ == "__main__":
- locale.setlocale(locale.LC_ALL, "")
+ setlocale(locale.LC_ALL, "")
gettext.install("pkg", "/usr/share/locale")
port = PORT_DEFAULT
--- a/src/modules/misc.py Thu Dec 18 13:08:47 2008 -0600
+++ b/src/modules/misc.py Thu Dec 18 11:15:47 2008 -0800
@@ -38,6 +38,7 @@
import time
import calendar
import shutil
+import locale
from stat import *
import pkg.urlhelpers as urlhelpers
@@ -300,6 +301,26 @@
raise PipeError, e
raise
+def setlocale(category, loc=None, printer=None):
+ """Wraps locale.setlocale(), falling back to the C locale if the desired
+ locale is broken or unavailable. The 'printer' parameter should be a
+ function which takes a string and displays it. If 'None' (the default),
+ setlocale() will print the message to stderr."""
+
+ if printer is None:
+ printer = emsg
+
+ try:
+ locale.setlocale(category, loc)
+ except locale.Error:
+ try:
+ dl = " '%s.%s'" % locale.getdefaultlocale()
+ except ValueError:
+ dl = ""
+ printer("Unable to set locale%s; locale package may be broken "
+ "or\nnot installed. Reverting to C locale." % dl)
+ locale.setlocale(category, "C")
+
def port_available(host, port):
"""Returns True if the indicated port is available to bind to;
otherwise returns False."""
--- a/src/packagemanager.py Thu Dec 18 13:08:47 2008 -0600
+++ b/src/packagemanager.py Thu Dec 18 11:15:47 2008 -0800
@@ -100,7 +100,7 @@
self.application_dir = os.environ["PACKAGE_MANAGER_ROOT"]
except KeyError:
self.application_dir = "/"
- locale.setlocale(locale.LC_ALL, '')
+ misc.setlocale(locale.LC_ALL, "")
for module in (gettext, gtk.glade):
module.bindtextdomain("pkg", self.application_dir + \
"/usr/share/locale")
--- a/src/updatemanager.py Thu Dec 18 13:08:47 2008 -0600
+++ b/src/updatemanager.py Thu Dec 18 11:15:47 2008 -0800
@@ -211,7 +211,7 @@
self.application_dir = os.environ["UPDATE_MANAGER_ROOT"]
except KeyError:
self.application_dir = "/"
- locale.setlocale(locale.LC_ALL, '')
+ misc.setlocale(locale.LC_ALL, "")
for module in (gettext, gtk.glade):
module.bindtextdomain("pkg", self.application_dir +
"/usr/share/locale")
--- a/src/updatemanagernotifier.py Thu Dec 18 13:08:47 2008 -0600
+++ b/src/updatemanagernotifier.py Thu Dec 18 11:15:47 2008 -0800
@@ -48,6 +48,7 @@
sys.exit(1)
import pkg.client.image as image
import pkg.client.progress as progress
+import pkg.misc as misc
# Put _() in the global namespace
import __builtin__
@@ -90,7 +91,7 @@
self.application_dir = os.environ["UPDATE_MANAGER_NOTIFIER_ROOT"]
except KeyError:
self.application_dir = "/"
- locale.setlocale(locale.LC_ALL, '')
+ misc.setlocale(locale.LC_ALL, "")
for module in (gettext, gtk.glade):
module.bindtextdomain("pkg", self.application_dir + \
"/usr/share/locale")