summaryrefslogtreecommitdiffstats
path: root/pykolab
diff options
context:
space:
mode:
authorJeroen van Meeuwen (Kolab Systems) <vanmeeuwen@kolabsys.com>2015-08-13 10:41:42 +0200
committerJeroen van Meeuwen (Kolab Systems) <vanmeeuwen@kolabsys.com>2015-08-13 10:41:42 +0200
commit3cb92d3f1f6f976cc5f78e60845a43dc117b8946 (patch)
tree1ba11229023aae36fdda3f93d2df1b6511933f0d /pykolab
parent213cf68e7995859d149973d9e20aa5fdf0387f37 (diff)
downloadpykolab-3cb92d3f1f6f976cc5f78e60845a43dc117b8946.tar.gz
Catch errors in translation, append UTF-8 if not specified to avoid translation-related tracebacks
Diffstat (limited to 'pykolab')
-rw-r--r--pykolab/translate.py14
1 files changed, 13 insertions, 1 deletions
diff --git a/pykolab/translate.py b/pykolab/translate.py
index ce9e406..7bac219 100644
--- a/pykolab/translate.py
+++ b/pykolab/translate.py
@@ -26,10 +26,18 @@ import gettext
import os
N_ = lambda x: x
-_ = lambda x: current.lgettext(x)
+
+# This function as such may, at times, cause tracebacks.
+#_ = lambda x: current.lgettext(x)
current = gettext.translation(domain, fallback=True)
+def _(x):
+ try:
+ return current.lgettext(x)
+ except Exception, errmsg:
+ return x
+
def getDefaultLangs():
languages = []
for envar in ('LANGUAGE', 'LC_ALL', 'LC_MESSAGES', 'LANG'):
@@ -46,11 +54,15 @@ def getDefaultLangs():
for nelang in gettext._expand_lang(lang):
if nelang not in nelangs:
nelangs.append(nelang)
+
return nelangs
def setUserLanguage(lang):
global current
+ if not len(lang.split('.')) > 1 and not lang.endswith('.UTF-8'):
+ lang = "%s.UTF-8" % (lang)
+
langs = []
for l in gettext._expand_lang(lang):
if l not in langs: