Skip to content

Commit

Permalink
Use localised date in popups (#307)
Browse files Browse the repository at this point in the history
* Localise dates

* make localize_date only return a string

* Update upnext popup to use localised date

* Update stillwatching popup to use localised date
  • Loading branch information
MoojMidge committed Oct 13, 2023
1 parent 649c711 commit b3ed0e5
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
4 changes: 2 additions & 2 deletions resources/lib/stillwatching.py
Expand Up @@ -6,7 +6,7 @@
from platform import machine
from xbmcgui import WindowXMLDialog
from statichelper import from_unicode
from utils import localize_time
from utils import localize_date, localize_time

ACTION_PLAYER_STOP = 13
ACTION_NAV_BACK = 92
Expand Down Expand Up @@ -54,7 +54,7 @@ def set_info(self):
self.setProperty('season', str(self.item.get('season', '')))
self.setProperty('episode', str(self.item.get('episode', '')))
self.setProperty('seasonepisode', episode_info)
self.setProperty('year', str(self.item.get('firstaired', '')))
self.setProperty('year', localize_date(self.item.get('firstaired', '')))
self.setProperty('rating', rating)
self.setProperty('playcount', str(self.item.get('playcount', 0)))
self.setProperty('runtime', str(self.item.get('runtime', '')))
Expand Down
4 changes: 2 additions & 2 deletions resources/lib/upnext.py
Expand Up @@ -7,7 +7,7 @@
from xbmc import Player
from xbmcgui import WindowXMLDialog
from statichelper import from_unicode
from utils import get_setting_bool, localize, localize_time
from utils import get_setting_bool, localize, localize_date, localize_time

ACTION_PLAYER_STOP = 13
ACTION_NAV_BACK = 92
Expand Down Expand Up @@ -59,7 +59,7 @@ def set_info(self):
self.setProperty('season', str(self.item.get('season', '')))
self.setProperty('episode', str(self.item.get('episode', '')))
self.setProperty('seasonepisode', episode_info)
self.setProperty('year', str(self.item.get('firstaired', '')))
self.setProperty('year', localize_date(self.item.get('firstaired', '')))
self.setProperty('rating', rating)
self.setProperty('playcount', str(self.item.get('playcount', 0)))
self.setProperty('runtime', str(self.item.get('runtime', '')))
Expand Down
19 changes: 19 additions & 0 deletions resources/lib/utils.py
Expand Up @@ -4,6 +4,8 @@
from __future__ import absolute_import, division, unicode_literals
import sys
import json
from datetime import date
from re import split as re_split
from xbmc import executeJSONRPC, getInfoLabel, getRegion, log as xlog, LOGDEBUG, LOGINFO
from xbmcaddon import Addon
from xbmcgui import Window
Expand Down Expand Up @@ -202,6 +204,23 @@ def localize(string_id):
return ADDON.getLocalizedString(string_id)


def localize_date(date_string):
"""Localize date format"""
date_format = getRegion('dateshort')

try:
# A number of assumptions are made here about date_string
# format to avoid having to import dateutil or similar
date_object = date(*(
int(part)
for part in re_split(r'[\W]', date_string)[:3]
))
except ValueError:
return date_string

return date_object.strftime(date_format)


def localize_time(time):
"""Localize time format"""
time_format = getRegion('time')
Expand Down

0 comments on commit b3ed0e5

Please sign in to comment.