1
1
# Miro - an RSS based video player application
2
# Copyright (C) 2005-2009 Participatory Culture Foundation
2
# Copyright (C) 2005-2010 Participatory Culture Foundation
4
4
# This program is free software; you can redistribute it and/or modify
5
5
# it under the terms of the GNU General Public License as published by
36
36
from miro.gtcache import gettext as _
37
37
from miro.gtcache import ngettext
39
def strftime_to_unicode(bytes):
39
def strftime_to_unicode(nbytes):
40
40
"""Convert the value return by strftime() to a unicode string.
42
42
By default, it's in whatever the default codeset is.
44
44
if gtcache.codeset is None:
47
return bytes.decode(gtcache.codeset)
47
return nbytes.decode(gtcache.codeset)
49
49
def download_rate(rate):
50
50
if rate >= (1 << 30):
71
71
return ngettext('%(num).0f hr', '%(num).0f hrs', t_hr, {"num": t_hr})
73
73
t_min = secs * 1.0 / 60
74
return ngettext('%(num).0f min', '%(num).0f mins', t_min, {"num": t_min})
74
return ngettext('%(num).0f min', '%(num).0f mins', t_min,
76
77
return ngettext('%(num)d sec', '%(num)d secs', secs, {"num": secs})
78
def size_string(bytes):
79
# when switching from the enclosure reported size to the downloader
80
# reported size, it takes a while to get the new size and the downloader
81
# returns -1. the user sees the size go to -1B which is weird....
82
# better to return an empty string.
83
if bytes == -1 or bytes == 0:
79
def size_string(nbytes):
80
# when switching from the enclosure reported size to the
81
# downloader reported size, it takes a while to get the new size
82
# and the downloader returns -1. the user sees the size go to -1B
83
# which is weird.... better to return an empty string.
84
if nbytes == -1 or nbytes == 0:
86
# FIXME this is a repeat of util.formatSizeForUser ... should
87
# FIXME this is a repeat of util.format_size_for_user ... should
87
88
# probably ditch one of them.
88
if bytes >= (1 << 30):
89
value = "%.1f" % (bytes / float(1 << 30))
89
if nbytes >= (1 << 30):
90
value = "%.1f" % (nbytes / float(1 << 30))
90
91
return _("%(size)s gb", {"size": value})
91
elif bytes >= (1 << 20):
92
value = "%.1f" % (bytes / float(1 << 20))
92
elif nbytes >= (1 << 20):
93
value = "%.1f" % (nbytes / float(1 << 20))
93
94
return _("%(size)s mb", {"size": value})
94
elif bytes >= (1 << 10):
95
value = "%.1f" % (bytes / float(1 << 10))
95
elif nbytes >= (1 << 10):
96
value = "%.1f" % (nbytes / float(1 << 10))
96
97
return _("%(size)s kb", {"size": value})
98
return _("%(size)s b", {"size": bytes})
99
return _("%(size)s b", {"size": nbytes})
100
101
def expiration_date(exp_date):
101
102
offset = exp_date - datetime.datetime.now()
133
134
math.ceil(offset.seconds/60.0),
134
135
{"count": math.ceil(offset.seconds/60.0)})
136
def release_date(release_date):
137
if release_date > datetime.datetime.min:
138
# figure out the date pieces, convert to unicode, then split it on "::" so
139
# we can run gettext on it allowing translators to reorder it.
141
m, d, y = strftime_to_unicode(release_date.strftime("%B::%d::%Y")).split("::")
142
return _("%(month)s %(dayofmonth)s, %(year)s", {"month": m, "dayofmonth": d, "year": y})
137
def release_date(rdate):
138
"""Takes a date object and returns the "month day, year"
141
If the rdate is below the minimum date, then this returns an
144
if rdate > datetime.datetime.min:
145
# figure out the date pieces, convert to unicode, then split
146
# it on "::" so we can run gettext on it allowing translators
147
# to reorder it. see bug 11662.
148
m, d, y = strftime_to_unicode(rdate.strftime("%B::%d::%Y")).split("::")
149
return _("%(month)s %(dayofmonth)s, %(year)s",
150
{"month": m, "dayofmonth": d, "year": y})
146
def release_date_slashes(release_date):
147
if release_date > datetime.datetime.min:
154
def release_date_slashes(rdate):
155
"""Takes a date object and returns the "MM/DD/YYYY"
158
If the rdate is below the minimum date, then this returns an
161
if rdate > datetime.datetime.min:
148
162
# note: %x is locale-appropriate
149
return strftime_to_unicode(release_date.strftime("%x"))
163
return strftime_to_unicode(rdate.strftime("%x"))