Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use localized format for idle-screen/gui #110

Merged
merged 5 commits into from
Mar 29, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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