[kupfer] main: Fix behavior with invalid locale



commit be86ee83f3ab31912a92572746290e1d2603a27e
Author: Ulrik Sverdrup <ulrik sverdrup gmail com>
Date:   Thu Aug 20 23:08:29 2009 +0200

    main: Fix behavior with invalid locale
    
    kupfer should run even though the user might specify an invalid locale
    (like LANG=bleh).

 kupfer/main.py |   13 ++++++++-----
 1 files changed, 8 insertions(+), 5 deletions(-)
---
diff --git a/kupfer/main.py b/kupfer/main.py
index ef61de1..c82bfe5 100644
--- a/kupfer/main.py
+++ b/kupfer/main.py
@@ -22,9 +22,9 @@ def setup_locale_and_gettext():
 	locale.bindtextdomain(package_name, localedir)
 	# to load in current locale properly for sorting etc
 	try:
-		locale.resetlocale()
+		locale.setlocale(locale.LC_ALL)
 	except locale.Error, e:
-		pass
+		print type(e), e
 
 setup_locale_and_gettext()
 
@@ -117,9 +117,12 @@ def print_banner():
 		"%(program)s: %(desc)s\n"
 		"	%(copyright)s\n"
 		"	%(website)s\n") % var
-	# Be careful about unicode here
-	enc = locale.getpreferredencoding()
-	print banner.encode(enc, "replace")
+
+	# Be careful about unicode here, since it might stop the whole program
+	try:
+		print banner
+	except UnicodeEncodeError, e:
+		print banner.encode("ascii", "replace")
 
 def main():
 	import sys



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]