diff --git a/bumblebee/modules/datetime.py b/bumblebee/modules/datetime.py index e1b9236..64df23e 100644 --- a/bumblebee/modules/datetime.py +++ b/bumblebee/modules/datetime.py @@ -6,6 +6,9 @@ Parameters: * datetime.format: strftime()-compatible formatting string * date.format : alias for datetime.format * time.format : alias for datetime.format + * datetime.locale: locale to use rather than the system default + * date.locale : alias for datetime.locale + * time.locale : alias for datetime.locale """ from __future__ import absolute_import @@ -13,8 +16,6 @@ import datetime import locale import bumblebee.engine -locale.setlocale(locale.LC_TIME, locale.getdefaultlocale()) - ALIASES = [ "date", "time" ] def default_format(module): @@ -28,9 +29,15 @@ def default_format(module): class Module(bumblebee.engine.Module): def __init__(self, engine, config): super(Module, self).__init__(engine, config, - bumblebee.output.Widget(full_text=self.get_time) - ) + bumblebee.output.Widget(full_text=self.get_time)) self._fmt = self.parameter("format", default_format(self.name)) + self._lcl = self.parameter("locale").split(".") + + # can't use the default in "parameter" because we split the + # string, while 'getdefaultlocale' already returns a tuple + if self._lcl is None: + self._lcl = locale.getdefaultlocale() + locale.setlocale(locale.LC_TIME, self._lcl) def get_time(self, widget): return datetime.datetime.now().strftime(self._fmt)