[module/datetime] Add more error handling to locale setting

If setting a locale fails with an exception, set to en_US.UTF-8 by
default.

fixes #159
This commit is contained in:
Tobias Witek 2018-10-01 19:30:44 +02:00
parent 7af04b0556
commit 20f48d4535

View file

@ -35,7 +35,10 @@ class Module(bumblebee.engine.Module):
if not l or l == (None, None): if not l or l == (None, None):
l = ('en_US', 'UTF-8') l = ('en_US', 'UTF-8')
lcl = self.parameter("locale", ".".join(l)) lcl = self.parameter("locale", ".".join(l))
locale.setlocale(locale.LC_TIME, lcl.split(".")) try:
locale.setlocale(locale.LC_TIME, lcl.split("."))
except Exception as e:
locale.setlocale(locale.LC_TIME, lcl.split("en_US.UTF-8"))
def get_time(self, widget): def get_time(self, widget):
enc = locale.getpreferredencoding() enc = locale.getpreferredencoding()