Skip to content

Commit

Permalink
Merge pull request #110 from domcross/improvement/gui-locale
Browse files Browse the repository at this point in the history
Use localized format for idle-screen/gui
  • Loading branch information
krisgesling authored Mar 29, 2021
2 parents fdec596 + 0b04db3 commit ab6af5a
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@

import mycroft.audio
from adapt.intent import IntentBuilder
from mycroft.util.format import nice_date, nice_duration, nice_time
from mycroft.util.format import (nice_date, nice_duration, nice_time,
date_time_format)
from mycroft.messagebus.message import Message
from mycroft import MycroftSkill, intent_handler
from mycroft.util.parse import (extract_datetime, fuzzy_match, extract_number,
Expand Down Expand Up @@ -60,6 +61,8 @@ def __init__(self):
self.default_timezone = None

def initialize(self):
date_time_format.cache(self.lang)

# Start a callback that repeats every 10 seconds
# TODO: Add mechanism to only start timer when UI setting
# is checked, but this requires a notifier for settings
Expand Down Expand Up @@ -622,12 +625,27 @@ def show_date_mark1(self, location, day):
def get_weekday(self, day=None, location=None):
if not day:
day = self.get_local_datetime(location)
return day.strftime("%A")
if self.lang in date_time_format.lang_config.keys():
localized_day_names = list(
date_time_format.lang_config[self.lang]['weekday'].values())
weekday = localized_day_names[day.weekday()]
else:
weekday = day.strftime("%A")
return weekday.capitalize()

def get_month_date(self, day=None, location=None):
if not day:
day = self.get_local_datetime(location)
return day.strftime("%B %d")
if self.lang in date_time_format.lang_config.keys():
localized_month_names = date_time_format.lang_config[self.lang]['month']
month = localized_month_names[str(int(day.strftime("%m")))]
else:
month = day.strftime("%B")
month = month.capitalize()
if self.config_core.get('date_format') == 'MDY':
return "{} {}".format(month, day.strftime("%d"))
else:
return "{} {}".format(day.strftime("%d"), month)

def get_year(self, day=None, location=None):
if not day:
Expand Down

0 comments on commit ab6af5a

Please sign in to comment.