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
Make use of new ungettext_lazy function at appropriate places. #702
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ | |
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you also fix this awful |
||
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): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would have put the strings in a list, then finally ugettext(", ").join(the_list) |
||
""" | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we fix this, we should do it right, because currently, it is awfully wrong, i18n-wise. The proper way is to duplicate the strings in each flag_* methods ('%(count)s comments were successfully flagged.', '%(count)s comments were successfully approved.', ...).