diff --git a/django/contrib/comments/admin.py b/django/contrib/comments/admin.py index a651baaadf..bca638182c 100644 --- a/django/contrib/comments/admin.py +++ b/django/contrib/comments/admin.py @@ -3,7 +3,7 @@ from __future__ import unicode_literals from django.contrib import admin from django.contrib.auth import get_user_model from django.contrib.comments.models import Comment -from django.utils.translation import ugettext_lazy as _, ungettext +from django.utils.translation import ugettext_lazy as _, ungettext, ungettext_lazy from django.contrib.comments import get_model from django.contrib.comments.views.moderation import perform_flag, perform_approve, perform_delete @@ -52,17 +52,20 @@ class CommentsAdmin(admin.ModelAdmin): def flag_comments(self, request, queryset): self._bulk_flag(request, queryset, perform_flag, - lambda n: ungettext('flagged', 'flagged', n)) + ungettext_lazy('%d comment was successfully flagged', + '%d comments were successfully flagged')) flag_comments.short_description = _("Flag selected comments") def approve_comments(self, request, queryset): self._bulk_flag(request, queryset, perform_approve, - lambda n: ungettext('approved', 'approved', n)) + ungettext_lazy('%d comment was successfully approved', + '%d comments were successfully approved')) approve_comments.short_description = _("Approve selected comments") def remove_comments(self, request, queryset): self._bulk_flag(request, queryset, perform_delete, - lambda n: ungettext('removed', 'removed', n)) + ungettext_lazy('%d comment was successfully removed', + '%d comments were successfully removed')) remove_comments.short_description = _("Remove selected comments") def _bulk_flag(self, request, queryset, action, done_message): @@ -75,10 +78,7 @@ class CommentsAdmin(admin.ModelAdmin): action(request, comment) n_comments += 1 - msg = ungettext('1 comment was successfully %(action)s.', - '%(count)s comments were successfully %(action)s.', - n_comments) - self.message_user(request, msg % {'count': n_comments, 'action': done_message(n_comments)}) + self.message_user(request, done_message % n_comments) # Only register the default admin if the model is the built-in comment model # (this won't be true if there's a custom comment app). 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): """ diff --git a/tests/regressiontests/comment_tests/tests/moderation_view_tests.py b/tests/regressiontests/comment_tests/tests/moderation_view_tests.py index 0f83d5e210..0abeff9687 100644 --- a/tests/regressiontests/comment_tests/tests/moderation_view_tests.py +++ b/tests/regressiontests/comment_tests/tests/moderation_view_tests.py @@ -1,9 +1,10 @@ -from __future__ import absolute_import +from __future__ import absolute_import, unicode_literals from django.contrib.auth.models import User, Permission from django.contrib.comments import signals from django.contrib.comments.models import Comment, CommentFlag from django.contrib.contenttypes.models import ContentType +from django.utils import translation from . import CommentTestCase @@ -281,3 +282,28 @@ class AdminActionsTests(CommentTestCase): response = self.client.get('/admin2/comments/comment/') self.assertEqual(response.status_code, 200) self.assertNotContains(response, '