This fixes gettext-ified strings to be unicodes

This commit is contained in:
Will Kahn-Greene 2013-11-01 10:43:51 -04:00
Родитель aa2bf37aa2
Коммит ff5af989df
7 изменённых файлов: 50 добавлений и 56 удалений

Просмотреть файл

@ -146,14 +146,14 @@ class AwardActivityStreamAtomFeedGenerator(Atom1Feed):
class AwardsFeed(BaseFeed):
"""Base class for all feeds listing awards"""
title = _('Recently awarded badges')
title = _(u'Recently awarded badges')
subtitle = None
json_feed_generator = AwardActivityStreamJSONFeedGenerator
atom_feed_generator = AwardActivityStreamAtomFeedGenerator
def item_title(self, obj):
return _('{badgetitle} awarded to {username}').format(
return _(u'{badgetitle} awarded to {username}').format(
badgetitle=obj.badge.title, username=obj.user.username)
def item_author_link(self, obj):
@ -185,7 +185,7 @@ class AwardsByUserFeed(AwardsFeed):
def get_object(self, request, format, username):
super(AwardsByUserFeed, self).get_object(request, format)
user = get_object_or_404(User, username=username)
self.title = _('Badges recently awarded to {username}').format(
self.title = _(u'Badges recently awarded to {username}').format(
username=user.username)
self.link = request.build_absolute_uri(
reverse('badger.views.awards_by_user', args=(user.username,)))
@ -204,7 +204,7 @@ class AwardsByBadgeFeed(AwardsFeed):
def get_object(self, request, format, slug):
super(AwardsByBadgeFeed, self).get_object(request, format)
badge = get_object_or_404(Badge, slug=slug)
self.title = _('Recent awards of "{badgetitle}"').format(
self.title = _(u'Recent awards of "{badgetitle}"').format(
badgetitle=badge.title)
self.link = request.build_absolute_uri(
reverse('badger.views.awards_by_badge', args=(badge.slug,)))
@ -222,7 +222,7 @@ class BadgesJSONFeedGenerator(BaseJSONFeedGenerator):
class BadgesFeed(BaseFeed):
"""Base class for all feeds listing badges"""
title = _('Recently created badges')
title = _(u'Recently created badges')
json_feed_generator = BadgesJSONFeedGenerator
@ -249,7 +249,7 @@ class BadgesByUserFeed(BadgesFeed):
def get_object(self, request, format, username):
super(BadgesByUserFeed, self).get_object(request, format)
user = get_object_or_404(User, username=username)
self.title = _('Badges recently created by {username}').format(
self.title = _(u'Badges recently created by {username}').format(
username=user.username)
self.link = request.build_absolute_uri(
reverse('badger.views.badges_by_user', args=(user.username,)))

Просмотреть файл

@ -7,7 +7,6 @@ from django import forms
from django.db import models
from django.contrib.auth.models import User, AnonymousUser
from django.forms import FileField, CharField, Textarea, ValidationError
from django.utils.translation import ugettext as _
from django.core.validators import validate_email
try:
@ -94,7 +93,7 @@ class MultipleItemsField(forms.Field):
# Enforce max number of items
if len(value) > self.max_items:
raise ValidationError(
_('{num} items entered, only {maxnum} allowed').format(
_(u'{num} items entered, only {maxnum} allowed').format(
num=len(value), maxnum=self.max_items))
# Validate each of the items
@ -108,7 +107,7 @@ class MultipleItemsField(forms.Field):
if len(invalid_items) > 0:
# TODO: l10n: Not all languages separate with commas
raise ValidationError(
_('These items were invalid: {itemlist}').format(
_(u'These items were invalid: {itemlist}').format(
itemlist=u', '.join(invalid_items)))
@ -122,12 +121,12 @@ class BadgeAwardForm(MyForm):
"""Form to create either a real or deferred badge award"""
# TODO: Needs a captcha?
emails = MultiEmailField(max_items=10,
help_text=_('Enter up to 10 email addresses for badge award '
'recipients'))
help_text=_(u'Enter up to 10 email addresses for badge award '
'recipients'))
description = CharField(
label='Explanation',
widget=Textarea, required=False,
help_text=_('Explain why this badge should be awarded'))
help_text=_(u'Explain why this badge should be awarded'))
class DeferredAwardGrantForm(MyForm):
@ -144,15 +143,15 @@ class MultipleClaimCodesField(MultipleItemsField):
DeferredAward.objects.get(claim_code=item)
return True
except DeferredAward.DoesNotExist:
raise ValidationError(_('No such claim code, {claimcode}').format(
raise ValidationError(_(u'No such claim code, {claimcode}').format(
claimcode=item))
class DeferredAwardMultipleGrantForm(MyForm):
email = forms.EmailField(
help_text=_('Email address to which claims should be granted'))
help_text=_(u'Email address to which claims should be granted'))
claim_codes = MultipleClaimCodesField(
help_text=_('Comma- or space-separated list of badge claim codes'))
help_text=_(u'Comma- or space-separated list of badge claim codes'))
class BadgeEditForm(MyModelForm):
@ -204,5 +203,5 @@ class BadgeNewForm(BadgeEditForm):
class BadgeSubmitNominationForm(MyForm):
"""Form to submit badge nominations"""
emails = MultiEmailField(max_items=10,
help_text=_('Enter up to 10 email addresses for badge award '
'nominees'))
help_text=_(
u'Enter up to 10 email addresses for badge award nominees'))

Просмотреть файл

@ -13,11 +13,6 @@ try:
except ImportError:
from django.core.urlresolvers import reverse
try:
from tower import ugettext_lazy as _
except ImportError:
from django.utils.translation import ugettext_lazy as _
import jingo
import jinja2
from jinja2 import evalcontextfilter, Markup, escape

Просмотреть файл

@ -17,27 +17,27 @@ if "notification" in settings.INSTALLED_APPS:
def create_notice_types(app, created_models, verbosity, **kwargs):
notices = (
("badge_edited", _("Badge edited"),
_("one of your badges has been edited")),
("badge_awarded", _("Badge awarded"),
_("one of your badges has been awarded to someone")),
("award_received", _("Award received"),
_("you have been awarded a badge")),
#("award_accepted", _("Badge award accepted"),
# _("someone has accepted an award for one of your badges")),
#("award_declined", _("Badge award declined"),
# _("someone has declined an award for one of your badges")),
("badge_edited", _(u"Badge edited"),
_(u"one of your badges has been edited")),
("badge_awarded", _(u"Badge awarded"),
_(u"one of your badges has been awarded to someone")),
("award_received", _(u"Award received"),
_(u"you have been awarded a badge")),
#("award_accepted", _(u"Badge award accepted"),
# _(u"someone has accepted an award for one of your badges")),
#("award_declined", _(u"Badge award declined"),
# _(u"someone has declined an award for one of your badges")),
# TODO: Notification on progress?
("nomination_submitted", _("Nomination submitted"),
_("someone has submitted a nomination for one of your badges")),
("nomination_approved", _("Nomination approved"),
_("a nomination you submitted for an award has been approved")),
("nomination_rejected", _("Nomination rejected"),
_("a nomination you submitted for an award has been rejected")),
("nomination_received", _("Nomination received"),
_("a nomination to award you a badge was approved")),
("nomination_accepted", _("Nomination accepted"),
_("a nomination you submitted for an award has been accepted")),
("nomination_submitted", _(u"Nomination submitted"),
_(u"someone has submitted a nomination for one of your badges")),
("nomination_approved", _(u"Nomination approved"),
_(u"a nomination you submitted for an award has been approved")),
("nomination_rejected", _(u"Nomination rejected"),
_(u"a nomination you submitted for an award has been rejected")),
("nomination_received", _(u"Nomination received"),
_(u"a nomination to award you a badge was approved")),
("nomination_accepted", _(u"Nomination accepted"),
_(u"a nomination you submitted for an award has been accepted")),
)
for notice in notices:
notification.create_notice_type(*notice)

Просмотреть файл

@ -438,7 +438,7 @@ class Badge(models.Model):
ordering = ['-modified', '-created']
permissions = (
('manage_deferredawards',
_('Can manage deferred awards for this badge')),
_(u'Can manage deferred awards for this badge')),
)
get_permissions_for = get_permissions_for
@ -456,7 +456,7 @@ class Badge(models.Model):
if self.image:
scaled_file = scale_image(self.image.file, IMG_MAX_SIZE)
if not scaled_file:
raise ValidationError(_('Cannot process image'))
raise ValidationError(_(u'Cannot process image'))
self.image.file = scaled_file
def save(self, **kwargs):
@ -1026,7 +1026,7 @@ class DeferredAward(models.Model):
ordering = ['-modified', '-created']
permissions = (
("grant_deferredaward",
_('Can grant deferred award to an email address')),
_(u'Can grant deferred award to an email address')),
)
get_permissions_for = get_permissions_for

Просмотреть файл

@ -73,6 +73,6 @@ def award_image(award):
@register.simple_tag
def user_award_list(badge, user):
if badge.allows_award_to(user):
return '<li><a class="award_badge" href="%s">%s</a></li>' % (reverse('badger.views.award_badge', args=[badge.slug, ]), _('Issue award'))
return '<li><a class="award_badge" href="%s">%s</a></li>' % (reverse('badger.views.award_badge', args=[badge.slug, ]), _(u'Issue award'))
else:
return ''

Просмотреть файл

@ -209,7 +209,7 @@ def delete(request, slug):
awards_count = badge.award_set.count()
if request.method == "POST":
messages.info(request, _('Badge "{badgetitle}" deleted.').format(
messages.info(request, _(u'Badge "{badgetitle}" deleted.').format(
badgetitle=badge.title))
badge.delete()
return HttpResponseRedirect(reverse('badger.views.badges_list'))
@ -239,11 +239,11 @@ def award_badge(request, slug):
description=description)
if result:
if not hasattr(result, 'claim_code'):
messages.info(request, _('Award issued to {email}').format(
messages.info(request, _(u'Award issued to {email}').format(
email=email))
else:
messages.info(request, _('Invitation to claim award '
'sent to {email}').format(email=email))
messages.info(request, _(
u'Invitation to claim award sent to {email}').format(email=email))
return HttpResponseRedirect(reverse('badger.views.detail',
args=(badge.slug,)))
@ -309,7 +309,7 @@ def award_delete(request, slug, id):
return HttpResponseForbidden('Award delete forbidden')
if request.method == "POST":
messages.info(request, _('Award for badge "{badgetitle}" deleted.').format(
messages.info(request, _(u'Award for badge "{badgetitle}" deleted.').format(
badgetitle=badge.title))
award.delete()
url = reverse('badger.views.detail', kwargs=dict(slug=slug))
@ -389,7 +389,7 @@ def claim_deferred_award(request, claim_code=None):
if grant_form.is_valid():
email = request.POST.get('email', None)
deferred_award.grant_to(email=email, granter=request.user)
messages.info(request, _('Award claim granted to {email}').format(
messages.info(request, _(u'Award claim granted to {email}').format(
email=email))
url = reverse('badger.views.detail',
args=(deferred_award.badge.slug,))
@ -463,7 +463,7 @@ def staff_tools(request):
for claim_code in codes:
da = DeferredAward.objects.get(claim_code=claim_code)
da.grant_to(email, request.user)
messages.info(request, _('Badge "{badgetitle}" granted to {email}').format(
messages.info(request, _(u'Badge "{badgetitle}" granted to {email}').format(
badgetitle=da.badge, email=email))
url = reverse('badger.views.staff_tools')
return HttpResponseRedirect(url)
@ -534,13 +534,13 @@ def nominate_for(request, slug):
try:
award = badge.nominate_for(nominee, request.user)
messages.info(request,
_('Nomination submitted for {email}').format(email=email))
_(u'Nomination submitted for {email}').format(email=email))
except BadgeAlreadyAwardedException:
messages.info(request,
_('Badge already awarded to {email}').format(email=email))
_(u'Badge already awarded to {email}').format(email=email))
except Exception:
messages.info(request,
_('Nomination failed for {email}').format(email=email))
_(u'Nomination failed for {email}').format(email=email))
return HttpResponseRedirect(reverse('badger.views.detail',
args=(badge.slug,)))