From 68ea048ce590afeac82fb631ba71d89981bc1890 Mon Sep 17 00:00:00 2001 From: Jonathan Harris Date: Sat, 12 Sep 2015 04:08:10 +0100 Subject: [PATCH] Fix for translated exception text. --- EDMarketConnector.py | 12 ++++++------ companion.py | 8 ++++++-- l10n.py | 9 +++++---- 3 files changed, 17 insertions(+), 12 deletions(-) diff --git a/EDMarketConnector.py b/EDMarketConnector.py index a9f5491b..8ef1778e 100755 --- a/EDMarketConnector.py +++ b/EDMarketConnector.py @@ -168,16 +168,16 @@ class AppWindow: flightlog.openlog() except Exception as e: if __debug__: print_exc() - self.status['text'] = str(e) + self.status['text'] = unicode(e) except companion.VerificationRequired: # don't worry about authentication now - prompt on query self.status['text'] = '' except companion.ServerError as e: - self.status['text'] = str(e) + self.status['text'] = unicode(e) except Exception as e: if __debug__: print_exc() - self.status['text'] = str(e) + self.status['text'] = unicode(e) self.cooldown() # callback after verification code @@ -186,7 +186,7 @@ class AppWindow: self.session.verify(code) except Exception as e: if __debug__: print_exc() - self.status['text'] = str(e) + self.status['text'] = unicode(e) else: return self.getandsend() # try again @@ -298,7 +298,7 @@ class AppWindow: # Companion API problem except companion.ServerError as e: - self.status['text'] = str(e) + self.status['text'] = unicode(e) if play_sound: hotkeymgr.play_bad() except requests.exceptions.ConnectionError as e: @@ -313,7 +313,7 @@ class AppWindow: except Exception as e: if __debug__: print_exc() - self.status['text'] = str(e) + self.status['text'] = unicode(e) if play_sound: hotkeymgr.play_bad() self.cooldown() diff --git a/companion.py b/companion.py index 4fe8e472..342b41f1 100644 --- a/companion.py +++ b/companion.py @@ -99,12 +99,16 @@ def listify(thing): class ServerError(Exception): - def __str__(self): + def __unicode__(self): return _('Error: Server is down') + def __str__(self): + return unicode(self).encode('utf-8') class CredentialsError(Exception): - def __str__(self): + def __unicode__(self): return _('Error: Invalid Credentials') + def __str__(self): + return unicode(self).encode('utf-8') class VerificationRequired(Exception): pass diff --git a/l10n.py b/l10n.py index 0c6ea08e..69afe699 100755 --- a/l10n.py +++ b/l10n.py @@ -54,13 +54,14 @@ class Translations: if __debug__: def translate(self, x): - if x in self.translations: - return self.translations[x] - else: + if not self.translations.get(x): print 'Missing translation: "%s"' % x + return x + else: + return self.translations.get(x) or x else: def translate(self, x): - return self.translations.get(x, x) + return self.translations.get(x, x) or x # Returns list of available language codes def available(self):