diff --git a/bartab/forms.py b/bartab/forms.py index d3c35de..6288577 100644 --- a/bartab/forms.py +++ b/bartab/forms.py @@ -1,12 +1,13 @@ from django import forms +from django.utils.translation import ugettext_lazy as _ from .models import BarTabSnapshot class ConsumptionForm(forms.Form): start_snapshot = forms.ModelChoiceField( - label="First to include", queryset=BarTabSnapshot.objects + label=_("First to include"), queryset=BarTabSnapshot.objects ) end_snapshot = forms.ModelChoiceField( - label="Last to include", queryset=BarTabSnapshot.objects + label=_("Last to include"), queryset=BarTabSnapshot.objects ) diff --git a/bartab/models.py b/bartab/models.py index ea26c69..447808a 100644 --- a/bartab/models.py +++ b/bartab/models.py @@ -6,6 +6,7 @@ from django.db.models import F, Sum, Value from django.db.models.functions import Coalesce from django.utils import timezone +from django.utils.translation import ugettext_lazy as _ from bartenders.models import BartenderShift @@ -83,10 +84,10 @@ class Meta: def clean(self): error = None if self.bartender_shift and self.custom_datetime: - error = "Can't have both bartender shift and custom datetime" + error = _("Can't have both bartender shift and custom datetime") if not self.bartender_shift and not self.custom_datetime: - error = "Must have either bartender shift or custom datetime" + error = _("Must have either bartender shift or custom datetime") if error: raise ValidationError( @@ -131,16 +132,16 @@ def __str__(self): class BarTabEntry(models.Model): - added_cash = models.BooleanField(blank=True, null=True, verbose_name="Kontant?") + added_cash = models.BooleanField(blank=True, null=True, verbose_name=_("Kontant?")) added = models.DecimalField(max_digits=9 + 2, decimal_places=2) used = models.DecimalField(max_digits=9 + 2, decimal_places=2) - raw_added = SumField(blank=True, verbose_name="Indsat") - raw_used = SumField(blank=True, verbose_name="Køb") + raw_added = SumField(blank=True, verbose_name=_("Indsat")) + raw_used = SumField(blank=True, verbose_name=_("Køb")) user = models.ForeignKey( BarTabUser, on_delete=models.CASCADE, - related_name="entries", - verbose_name="Bruger", + related_name=_("entries"), + verbose_name=_("Bruger"), ) snapshot = models.ForeignKey( BarTabSnapshot, on_delete=models.CASCADE, related_name="entries" @@ -157,7 +158,7 @@ def clean(self): if self.raw_added: self.added = self.raw_added.value if self.added_cash == None and self.added != 0: - raise ValidationError("Vælg kontant eller ej.") + raise ValidationError(_("Vælg kontant eller ej.")) if self.raw_used: self.used = self.raw_used.value diff --git a/bartab/sumfield.py b/bartab/sumfield.py index c5d256c..9fee0f9 100644 --- a/bartab/sumfield.py +++ b/bartab/sumfield.py @@ -4,6 +4,7 @@ from django import forms from django.core.exceptions import ValidationError from django.db import models +from django.utils.translation import ugettext_lazy as _ SumValue = namedtuple("SumValue", ["string", "value"]) @@ -27,7 +28,7 @@ def clean(self, value): try: return parse_sum(value) except (ValueError, InvalidOperation): - raise ValidationError("Invalid sum") + raise ValidationError(_("Invalid sum")) def prepare_value(self, value): if isinstance(value, str) or value == None: diff --git a/bartab/templates/bartab/consumption.html b/bartab/templates/bartab/consumption.html index cfbdf61..5acd6ba 100644 --- a/bartab/templates/bartab/consumption.html +++ b/bartab/templates/bartab/consumption.html @@ -1,18 +1,19 @@ {% extends "admin/base_site.html" %} {% block content %} +{% load i18n %}
{% if result %} -# | -Navn | -Forbrug | +{% translate "Navn" %} | +{% translate "Forbrug" %} | {{ shift.responsible.name }} | {% for bartender in shift.other_bartenders.all %} - {% if bartender.first_bartender_shift == shift %}{{ bartender.name }}{% else %}{{ bartender.name }}{% endif %}{% if not forloop.last %},{% endif %} + {% translate "Bartender's first shift" as FIRST_SHIFT_TEXT %} + {% if bartender.first_bartender_shift == shift %}{{ bartender.name }}{% else %}{{ bartender.name }}{% endif %}{% if not forloop.last %},{% endif %} {% endfor %} | {% if user.is_staff %} @@ -70,11 +71,12 @@{{ shift.start_date | date:"d M" }}{% if show_all %} {{ shift.start_date.year }}{% endif %} - {{ shift.end_date | date:"d M" }}{% if show_all %} {{ shift.end_date.year }}{% endif %} | {% for responsible in shift.responsibles.all %} - {% if responsible.first_deposit_shift == shift %}{{ responsible.name }}{% else %}{{ responsible.name }}{% endif %}{% if not forloop.last %},{% endif %} + {% translate "Bartender's first deposit shift" as FIRST_DEPOSIT_SHIFT_TEXT %} + {% if responsible.first_deposit_shift == shift %}{{ responsible.name }}{% else %}{{ responsible.name }}{% endif %}{% if not forloop.last %},{% endif %} {% endfor %} | {% if user.is_staff %} -Edit | +{% translate "Edit" %} | {% endif %} {% endfor %} diff --git a/bartenders/views.py b/bartenders/views.py index c00e9f1..9d7462c 100644 --- a/bartenders/views.py +++ b/bartenders/views.py @@ -9,6 +9,7 @@ from django.db import IntegrityError from django.shortcuts import get_object_or_404, redirect, reverse from django.utils import timezone +from django.utils.translation import ugettext_lazy as _ from django.views.generic import ( CreateView, FormView, @@ -58,7 +59,7 @@ def form_valid(self, form): # Send email to best form.send_email(self.object.pk) - messages.success(self.request, "Din ansøgning er blevet indsendt.") + messages.success(self.request, _("Din ansøgning er blevet indsendt.")) return response @@ -104,7 +105,7 @@ class UserBarplan(ICalFeed): product_id = "-//fredagscafeen.dk//UserBarplan//EN" timezone = "UTC" file_name = "barvagter.ics" - title = "Barvagter" + title = _("Barvagter") def get_object(self, request, **kwargs): # kwargs['username'] is None if we need to show all shifts @@ -127,8 +128,10 @@ def item_end_datetime(self, shift): return shift.end_datetime def item_description(self, shift): - return f"""Responsible: {shift.responsible.name} -Other bartenders: {", ".join(b.name for b in shift.other_bartenders.all())}""" + responsible_text = _("Responsible") + other_text = _("Other bartenders") + return f"""{responsible_text}: {shift.responsible.name} +{other_text}: {", ".join(b.name for b in shift.other_bartenders.all())}""" def item_link(self, shift): return f"{settings.SELF_URL}barplan/" @@ -141,7 +144,7 @@ class UserDepositShifts(ICalFeed): product_id = "-//fredagscafeen.dk//UserDepositShifts//EN" timezone = "UTC" file_name = "pantvagter.ics" - title = "Pantvagter" + title = _("Pantvagter") def get_object(self, request, **kwargs): # kwargs['username'] is None if we need to show all shifts @@ -164,9 +167,8 @@ def item_end_datetime(self, shift): return shift.end_date def item_description(self, shift): - return ( - f"""Responsibles: {", ".join(b.name for b in shift.responsibles.all())}""" - ) + responsible_text = _("Responsible") + return f"""{responsible_text}: {", ".join(b.name for b in shift.responsibles.all())}""" def item_link(self, shift): return f"{settings.SELF_URL}barplan/" @@ -274,15 +276,16 @@ def get_context_data(self, **kwargs): return context def form_valid(self, form): - messages.success(self.request, "Profil opdateret") + messages.success(self.request, _("Profil opdateret")) redirect_url = super().form_valid(form) if "deactivate" in self.request.POST: self.object.isActiveBartender = False self.object.save() active_count = Bartender.objects.filter(isActiveBartender=True).count() + inactive_text = "Bartender har meldt sig inaktiv" send_template_email( - subject=f"Bartender har meldt sig inaktiv: {self.object.name}", + subject=f"{inactive_text}: {self.object.name}", body_template=f"""Dette er en automatisk email. {self.object.name} har meldt sig inaktiv. @@ -342,7 +345,7 @@ def form_valid(self, form): data = form.cleaned_data urls = data["urls"].split() if len(urls) < votees.count(): - form.add_error("urls", f"Atleast {votees.count()} urls required") + form.add_error("urls", f"At least {votees.count()} urls required") return self.form_invalid(form) try: poll = Poll.objects.create(name=data["name"]) diff --git a/events/admin.py b/events/admin.py index 0fe38e3..db86237 100644 --- a/events/admin.py +++ b/events/admin.py @@ -1,5 +1,6 @@ from django import forms from django.contrib import admin +from django.utils.translation import ugettext_lazy as _ from bartenders.models import Bartender @@ -12,7 +13,7 @@ class Meta: fields = ["name"] chosen_options = forms.CharField( - label="Chosen options", disabled=True, widget=forms.Textarea + label=_("Chosen options"), disabled=True, widget=forms.Textarea ) def get_initial_for_field(self, field, fieldname): @@ -68,8 +69,8 @@ class Meta: fields = "__all__" default_may_attends = forms.CharField( - label="Default allowed attendees", - help_text="Can be overwritten using the whitelist and blacklist above.", + label=_("Default allowed attendees"), + help_text=_("Can be overwritten using the whitelist and blacklist above."), disabled=True, widget=forms.Textarea, ) @@ -82,8 +83,8 @@ def get_initial_for_field(self, field, fieldname): if self.instance.may_attend_default(b): s += f"- {b}\n" allowed += 1 - - return f"{allowed} bartenders:\n" + s.strip() + bartenders = _("bartenders") + return f"{allowed} {bartenders}:\n" + s.strip() return super().get_initial_for_field(field, fieldname) diff --git a/events/forms.py b/events/forms.py index 918902c..8208ba6 100644 --- a/events/forms.py +++ b/events/forms.py @@ -87,14 +87,19 @@ def clean(self): if not option: self.add_error( - field, f"Du skal udfylde {choice.name}, når du deltager" + field, + _("Du skal udfylde %(choice_name)s, når du deltager") + % {"choice_name": choice.name}, ) continue if not option.can_bartender_choose(self.bartender): self.add_error( field, - f"Der er for mange der har valgt {option.option}. Vælg noget andet.", + _( + "Der er for mange der har valgt %(option_option)s. Vælg noget andet." + ) + & {"option_option": option.option}, ) def save(self): diff --git a/events/views.py b/events/views.py index d168919..4771303 100644 --- a/events/views.py +++ b/events/views.py @@ -2,6 +2,7 @@ from django.contrib import messages from django.http import HttpResponseBadRequest, HttpResponseForbidden from django.shortcuts import redirect +from django.utils.translation import ugettext_lazy as _ from django.views.generic import TemplateView from django_ical.views import ICalFeed @@ -53,11 +54,11 @@ def post(self, request, *args, **kwargs): event_id = request.POST.get("event_id") event = Event.objects.get(id=event_id) except Event.DoesNotExist: - return HttpResponseBadRequest("Event with id does not exist") + return HttpResponseBadRequest(_("Event with id does not exist")) bartender = self.get_bartender() if not bartender or not event.may_attend(bartender): - return HttpResponseForbidden("Not logged in as an active bartender") + return HttpResponseForbidden(_("Not logged in as an active bartender")) form = EventResponseForm(request.POST, event=event, bartender=bartender) if not form.is_valid(): @@ -67,7 +68,10 @@ def post(self, request, *args, **kwargs): form.save() - messages.success(request, f"Opdateret tilmelding til {event.name}") + messages.success( + request, + _("Opdateret tilmelding til %(event_name)s") % {"event_name": event.name}, + ) return redirect("events") @@ -75,7 +79,7 @@ class EventFeed(ICalFeed): product_id = "-//fredagscafeen.dk//Events//EN" timezone = "UTC" file_name = "events.ics" - title = "Bartender Events" + title = _("Bartender Events") def items(self): return Event.objects.all() @@ -93,7 +97,8 @@ def item_end_datetime(self, event): return event.end_datetime def item_description(self, event): - return f"""Tilmeldingsfrist: {event.response_deadline} + tilmeldingsfrist = _("Tilmeldingsfrist") + return f"""{tilmeldingsfrist}: {event.response_deadline} {event.description}""" diff --git a/locale/da/LC_MESSAGES/django.mo b/locale/da/LC_MESSAGES/django.mo index c20b14d..cdc0d4f 100644 Binary files a/locale/da/LC_MESSAGES/django.mo and b/locale/da/LC_MESSAGES/django.mo differ diff --git a/web/views.py b/web/views.py index d309dc6..506ab8b 100644 --- a/web/views.py +++ b/web/views.py @@ -2,6 +2,7 @@ from django.contrib import messages from django.contrib.auth import REDIRECT_FIELD_NAME, authenticate, login, logout from django.shortcuts import redirect +from django.utils.translation import ugettext_lazy as _ from django.views.decorators.http import require_GET, require_POST from django.views.generic import TemplateView from django.views.generic.edit import FormView @@ -43,7 +44,9 @@ def form_valid(self, form): form.send_email(self.request.GET.get("next")) messages.success( self.request, - "Login mail sendt: Tryk på linket i din modtagede mail for at logge ind.", + _( + "Login mail sendt: Tryk på linket i din modtagede mail for at logge ind." + ), ) return super().form_valid(form)
---|