summaryrefslogtreecommitdiff
path: root/django/utils
diff options
context:
space:
mode:
authorAlexey Boriskin <sun.void@gmail.com>2013-02-02 00:22:20 +0400
committerClaude Paroz <claude@2xlibre.net>2013-02-06 22:01:55 +0100
commitd18f796a481e79a3800d4672d6189e4c496cce3d (patch)
treeba5734c5c01b61fde37ea2ab37bc88c637c36764 /django/utils
parentd7504a3d7b8645bdb979bab7ded0e9a9b6dccd0e (diff)
Fixed #19704 -- Make use of new ungettext_lazy function at appropriate places
Diffstat (limited to 'django/utils')
-rw-r--r--django/utils/timesince.py22
1 files changed, 11 insertions, 11 deletions
diff --git a/django/utils/timesince.py b/django/utils/timesince.py
index 1721f097bd..d70ab2ffe1 100644
--- a/django/utils/timesince.py
+++ b/django/utils/timesince.py
@@ -3,7 +3,7 @@ from __future__ import unicode_literals
import datetime
from django.utils.timezone import is_aware, utc
-from django.utils.translation import ungettext, ugettext
+from django.utils.translation import ugettext, ungettext_lazy
def timesince(d, now=None, reversed=False):
"""
@@ -19,12 +19,12 @@ def timesince(d, now=None, reversed=False):
Adapted from http://blog.natbat.co.uk/archive/2003/Jun/14/time_since
"""
chunks = (
- (60 * 60 * 24 * 365, lambda n: ungettext('year', 'years', n)),
- (60 * 60 * 24 * 30, lambda n: ungettext('month', 'months', n)),
- (60 * 60 * 24 * 7, lambda n : ungettext('week', 'weeks', n)),
- (60 * 60 * 24, lambda n : ungettext('day', 'days', n)),
- (60 * 60, lambda n: ungettext('hour', 'hours', n)),
- (60, lambda n: ungettext('minute', 'minutes', n))
+ (60 * 60 * 24 * 365, ungettext_lazy('%d year', '%d years')),
+ (60 * 60 * 24 * 30, ungettext_lazy('%d month', '%d months')),
+ (60 * 60 * 24 * 7, ungettext_lazy('%d week', '%d weeks')),
+ (60 * 60 * 24, ungettext_lazy('%d day', '%d days')),
+ (60 * 60, ungettext_lazy('%d hour', '%d hours')),
+ (60, ungettext_lazy('%d minute', '%d minutes'))
)
# Convert datetime.date to datetime.datetime for comparison.
if not isinstance(d, datetime.datetime):
@@ -40,19 +40,19 @@ def timesince(d, now=None, reversed=False):
since = delta.days * 24 * 60 * 60 + delta.seconds
if since <= 0:
# d is in the future compared to now, stop processing.
- return '0 ' + ugettext('minutes')
+ return ugettext('0 minutes')
for i, (seconds, name) in enumerate(chunks):
count = since // seconds
if count != 0:
break
- s = ugettext('%(number)d %(type)s') % {'number': count, 'type': name(count)}
+ result = name % count
if i + 1 < len(chunks):
# Now get the second item
seconds2, name2 = chunks[i + 1]
count2 = (since - (seconds * count)) // seconds2
if count2 != 0:
- s += ugettext(', %(number)d %(type)s') % {'number': count2, 'type': name2(count2)}
- return s
+ result += ugettext(', ') + name2 % count2
+ return result
def timeuntil(d, now=None):
"""