Skip to content

Commit

Permalink
Refactor song time texts
Browse files Browse the repository at this point in the history
There are three:
1. About dialog
2. The main status bar
3. Library (in the item listings for genre, artist, and album views)

This updates the localization strings and should be more useful way to
handle for localizers.
  • Loading branch information
hobophobe committed Jan 9, 2013
1 parent 4401fb5 commit 284a8c6
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 49 deletions.
45 changes: 22 additions & 23 deletions sonata/about.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,35 +141,34 @@ def about_shortcuts(self, _button):
self.shortcuts_dialog.run()

def statstext(self, stats):
# XXX translate expressions, not words
statslabel = '%s %s.\n' % (stats['songs'],
ngettext('song', 'songs',
int(stats['songs'])))
statslabel += '%s %s.\n' % (stats['albums'],
ngettext('album', 'albums',
int(stats['albums'])))
statslabel += '%s %s.\n' % (stats['artists'],
ngettext('artist', 'artists',
int(stats['artists'])))
song_count = int(stats['songs'])
song_text = ngettext('{count} song.', '{count} songs.',
song_count).format(count=song_count)
album_count = int(stats['albums'])
album_text = ngettext('{count} album.', '{count} albums.',
album_count).format(count=album_count)
artist_count = int(stats['artists'])
artist_text = ngettext('{count} artist.', '{count} artists.',
artist_count).format(count=artist_count)

try:
db_playtime = float(stats['db_playtime'])
hours_of_playtime = int(misc.convert_time(db_playtime).split(':')[-3])
hours = int(misc.convert_time(db_playtime).split(':')[-3])
except:
hours_of_playtime = 0
if hours_of_playtime >= 24:
days_of_playtime = round(hours_of_playtime / 24, 1)
statslabel += '%s %s.' % (days_of_playtime,
ngettext('day of bliss',
'days of bliss',
int(days_of_playtime)))
hours = 0
if hours >= 24:
days = round(hours / 24, 1)
time_text = ngettext('{count} day of bliss.',
'{count} days of bliss.',
days).format(count=days)
else:
statslabel += '%s %s.' % (hours_of_playtime,
ngettext('hour of bliss',
'hours of bliss',
int(hours_of_playtime)))
time_text = ngettext('{count} hour of bliss.',
'{count} hours of bliss.',
hours).format(count=hours)

return statslabel
parts = (song_text, album_text, artist_text, time_text)
live_parts = [part for part in parts if part is not None]
return '\n'.join(live_parts)

def about_load(self, stats):
self.builder = ui.builder('about')
Expand Down
26 changes: 15 additions & 11 deletions sonata/library.py
Original file line number Diff line number Diff line change
Expand Up @@ -922,20 +922,24 @@ def add_display_info(self, num_songs, playtime):
seconds -= 3600 * hours
minutes = seconds // 60
seconds -= 60 * minutes
songs_text = ngettext('{count} song', '{count} songs',
num_songs).format(count=num_songs)
seconds_text = ngettext('{count} second', '{count} seconds',
seconds).format(count=seconds)
minutes_text = ngettext('{count} minute', '{count} minutes',
minutes).format(count=minutes)
hours_text = ngettext('{count} hour', '{count} hours',
hours).format(count=hours)
time_parts = [songs_text]
if hours > 0:
return "\n<small><span weight='light'>%s %s, %s %s, %s %s</span></small>" \
% (num_songs, ngettext('song', 'songs', num_songs),
seconds, ngettext('hour', 'hours', hours),
seconds, ngettext('minute', 'minutes', minutes))
time_parts.extend([hours_text, minutes_text])
elif minutes > 0:
return "\n<small><span weight='light'>%s %s, %s %s, %s %s</span></small>" \
% (num_songs, ngettext('song', 'songs', num_songs),
minutes, ngettext('minute', 'minutes', minutes),
seconds, ngettext('second', 'secondes', seconds))
time_parts.extend([minutes_text, seconds_text])
else:
return "\n<small><span weight='light'>%s %s, %s %s</span></small>" \
% (num_songs, ngettext('song', 'songs', num_songs),
seconds, ngettext('second', 'secondes', seconds))
time_parts.extend([seconds_text])
display_markup = "\n<small><span weight='light'>{}</span></small>"
display_text = ', '.join(time_parts)
return display_markup.format(display_text)

def library_retain_selection(self, prev_selection, prev_selection_root,
prev_selection_parent):
Expand Down
32 changes: 17 additions & 15 deletions sonata/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -1615,31 +1615,33 @@ def update_statusbar(self, updatingdb=False):
# FIXME _ is for localization, temporarily __
hours, mins, __ = misc.convert_time_raw(self.current.total_time)
# Show text:
songs_text = ngettext('song', 'songs',
int(self.status['playlistlength']))
songs_string = "{} {}".format(self.status['playlistlength'],
songs_text)
songs_count = int(self.status['playlistlength'])
songs_text = ngettext('{count} song', '{count} songs',
songs_count).format(count=songs_count)
time_parts = []
if hours >= 24:
days = int(hours / 24)
hours = hours - (days * 24)
if days:
days_text = ngettext('day', 'days', days)
time_parts.append("{} {}".format(days, days_text))
days_text = ngettext('{count} day', '{count} days',
days).format(count=days)
time_parts.append(days_text)
if hours:
hours_text = ngettext('hour', 'hours', hours)
time_parts.append("{} {}".format(hours, hours_text))
hours_text = ngettext('{count} hour', '{count} hours',
hours).format(count=hours)
time_parts.append(hours_text)
if mins:
mins_text = ngettext('minute', 'minutes', mins)
time_parts.append("{} {}".format(mins, mins_text))
time_string = ', '.join([part for part in time_parts if part])
if float(self.status['playlistlength']) > 0:
status_text = "{}: {}".format(songs_string, time_string)
mins_text = ngettext('{count} minute', '{count} minutes',
mins).format(count=mins)
time_parts.append(mins_text)
time_text = ', '.join([part for part in time_parts if part])
if int(self.status['playlistlength']) > 0:
status_text = "{}: {}".format(songs_text, time_text)
else:
status_text = ''
if updatingdb:
update_string = _('(updating mpd)')
status_text = "{}: {}".format(status_text, update_string)
update_text = _('(updating mpd)')
status_text = "{}: {}".format(status_text, update_text)
else:
status_text = ''
if status_text != self.last_status_text:
Expand Down

0 comments on commit 284a8c6

Please sign in to comment.