Skip to content

Commit

Permalink
Merge pull request #13 from fredagscafeen/Internationalization
Browse files Browse the repository at this point in the history
Added more translations
  • Loading branch information
AndersSeverinsen authored Jul 11, 2024
2 parents 9d1b3d6 + 076153d commit 135c863
Show file tree
Hide file tree
Showing 11 changed files with 65 additions and 42 deletions.
5 changes: 3 additions & 2 deletions bartab/forms.py
Original file line number Diff line number Diff line change
@@ -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
)
17 changes: 9 additions & 8 deletions bartab/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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"
Expand All @@ -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
3 changes: 2 additions & 1 deletion bartab/sumfield.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"])

Expand All @@ -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:
Expand Down
9 changes: 5 additions & 4 deletions bartab/templates/bartab/consumption.html
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
{% extends "admin/base_site.html" %}
{% block content %}
{% load i18n %}
<form method="post">
{% csrf_token %}
{{ form.as_p }}
<input type="submit" value="Submit">
<input type="submit" value="{% translate "Submit" %}">
</form>
{% if result %}
<h2>Result</h1>
<h2>{% translate "Result" %}</h1>
<table>
<thead>
<tr>
<th>#</th>
<th>Navn</th>
<th>Forbrug</th>
<th>{% translate "Navn" %}</th>
<th>{% translate "Forbrug" %}</th>
</tr>
</thead>
<tbody>
Expand Down
8 changes: 5 additions & 3 deletions bartenders/templates/barplan.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ <h2>{% translate "Barplan" %}</h2>
<td class="col-md-3">{{ shift.responsible.name }}</td>
<td class="col-md-7">
{% for bartender in shift.other_bartenders.all %}
{% if bartender.first_bartender_shift == shift %}<b title="Bartender's first shift">{{ bartender.name }}</b>{% else %}{{ bartender.name }}{% endif %}{% if not forloop.last %},{% endif %}
{% translate "Bartender's first shift" as FIRST_SHIFT_TEXT %}
{% if bartender.first_bartender_shift == shift %}<b title="{{ FIRST_SHIFT_TEXT }}">{{ bartender.name }}</b>{% else %}{{ bartender.name }}{% endif %}{% if not forloop.last %},{% endif %}
{% endfor %}
</td>
{% if user.is_staff %}
Expand Down Expand Up @@ -70,11 +71,12 @@ <h2>{% translate "Pantvagter" %}</h2>
<td class="col-md-2">{{ 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 %}</td>
<td class="col-md-9">
{% for responsible in shift.responsibles.all %}
{% if responsible.first_deposit_shift == shift %}<b title="Bartender's first deposit shift">{{ responsible.name }}</b>{% 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 %}<b title="{{ FIRST_DEPOSIT_SHIFT_TEXT }}">{{ responsible.name }}</b>{% else %}{{ responsible.name }}{% endif %}{% if not forloop.last %},{% endif %}
{% endfor %}
</td>
{% if user.is_staff %}
<td class="hidden-xs col-md-1"><a href="/admin/bartenders/boardmemberdepositshift/{{ shift.id }}">Edit</a></td>
<td class="hidden-xs col-md-1"><a href="/admin/bartenders/boardmemberdepositshift/{{ shift.id }}">{% translate "Edit" %}</a></td>
{% endif %}
</tr>
{% endfor %}
Expand Down
25 changes: 14 additions & 11 deletions bartenders/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand All @@ -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/"
Expand All @@ -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
Expand All @@ -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/"
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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"])
Expand Down
11 changes: 6 additions & 5 deletions events/admin.py
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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):
Expand Down Expand Up @@ -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,
)
Expand All @@ -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)

Expand Down
9 changes: 7 additions & 2 deletions events/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
15 changes: 10 additions & 5 deletions events/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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():
Expand All @@ -67,15 +68,18 @@ 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")


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()
Expand 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}"""

Expand Down
Binary file modified locale/da/LC_MESSAGES/django.mo
Binary file not shown.
5 changes: 4 additions & 1 deletion web/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit 135c863

Please sign in to comment.