From bd4705b77f572bfd5ab475086732785d97efb022 Mon Sep 17 00:00:00 2001 From: "Christopher C. Wells" Date: Sat, 13 Apr 2019 22:51:44 -0700 Subject: [PATCH] Add translateable strings support in core app. --- core/forms.py | 5 +- core/models.py | 90 +++++++++++++------ core/templates/core/child_confirm_delete.html | 18 ++-- core/templates/core/child_detail.html | 16 ++-- core/templates/core/child_form.html | 13 +-- core/templates/core/child_list.html | 20 ++--- .../core/diaperchange_confirm_delete.html | 14 +-- core/templates/core/diaperchange_form.html | 15 ++-- core/templates/core/diaperchange_list.html | 27 +++--- .../core/feeding_confirm_delete.html | 14 +-- core/templates/core/feeding_form.html | 15 ++-- core/templates/core/feeding_list.html | 28 +++--- core/templates/core/note_confirm_delete.html | 14 +-- core/templates/core/note_form.html | 15 ++-- core/templates/core/note_list.html | 20 ++--- core/templates/core/sleep_confirm_delete.html | 14 +-- core/templates/core/sleep_form.html | 15 ++-- core/templates/core/sleep_list.html | 24 ++--- core/templates/core/timer_confirm_delete.html | 14 +-- core/templates/core/timer_detail.html | 24 +++-- core/templates/core/timer_form.html | 14 +-- core/templates/core/timer_list.html | 20 ++--- core/templates/core/timer_nav.html | 16 ++-- .../core/tummytime_confirm_delete.html | 14 +-- core/templates/core/tummytime_form.html | 15 ++-- core/templates/core/tummytime_list.html | 25 +++--- .../templates/core/weight_confirm_delete.html | 14 +-- core/templates/core/weight_form.html | 13 +-- core/templates/core/weight_list.html | 20 ++--- core/views.py | 13 +-- 30 files changed, 318 insertions(+), 261 deletions(-) diff --git a/core/forms.py b/core/forms.py index f6621ee7..9e9b9a07 100644 --- a/core/forms.py +++ b/core/forms.py @@ -1,7 +1,8 @@ # -*- coding: utf-8 -*- from django import forms -from django.utils import timezone from django.conf import settings +from django.utils import timezone +from django.utils.translation import gettext as _ from core import models @@ -77,7 +78,7 @@ class ChildDeleteForm(forms.ModelForm): confirm_name = self.cleaned_data['confirm_name'] if confirm_name != str(self.instance): raise forms.ValidationError( - 'Name does not match child name.', code='confirm_mismatch') + _('Name does not match child name.'), code='confirm_mismatch') return confirm_name def save(self, commit=True): diff --git a/core/models.py b/core/models.py index 38e5c27a..0656b0ad 100644 --- a/core/models.py +++ b/core/models.py @@ -6,6 +6,7 @@ from django.core.exceptions import ValidationError from django.db import models from django.template.defaultfilters import slugify from django.utils import timezone +from django.utils.translation import gettext_lazy as _ def validate_date(date, field_name): @@ -17,7 +18,7 @@ def validate_date(date, field_name): """ if date and date > timezone.localdate(): raise ValidationError( - {field_name: 'Date can not be in the future.'}, + {field_name: _('Date can not be in the future.')}, code='date_invalid') @@ -31,10 +32,10 @@ def validate_duration(model, max_duration=timedelta(hours=24)): if model.start and model.end: if model.start > model.end: raise ValidationError( - 'Start time must come before end time.', + _('Start time must come before end time.'), code='end_before_start') if model.end - model.start > max_duration: - raise ValidationError('Duration too long.', code='max_duration') + raise ValidationError(_('Duration too long.'), code='max_duration') def validate_unique_period(queryset, model): @@ -50,7 +51,7 @@ def validate_unique_period(queryset, model): if model.start and model.end: if queryset.filter(start__lte=model.end, end__gte=model.start): raise ValidationError( - 'Another entry intersects the specified time period.', + _('Another entry intersects the specified time period.'), code='period_intersection') @@ -63,7 +64,7 @@ def validate_time(time, field_name): """ if time and time > timezone.localtime(): raise ValidationError( - {field_name: 'Date/time can not be in the future.'}, + {field_name: _('Date/time can not be in the future.')}, code='time_invalid') @@ -84,7 +85,8 @@ class Child(models.Model): class Meta: default_permissions = ('view', 'add', 'change', 'delete') ordering = ['last_name', 'first_name'] - verbose_name_plural = 'Children' + verbose_name = _('Child') + verbose_name_plural = _('Children') def __str__(self): return '{} {}'.format(self.first_name, self.last_name) @@ -103,15 +105,19 @@ class Child(models.Model): class DiaperChange(models.Model): model_name = 'diaperchange' child = models.ForeignKey( - 'Child', related_name='diaper_change', on_delete=models.CASCADE) + 'Child', + on_delete=models.CASCADE, + related_name='diaper_change', + verbose_name=_('Child') + ) time = models.DateTimeField(blank=False, null=False) wet = models.BooleanField() solid = models.BooleanField() color = models.CharField(max_length=255, blank=True, choices=[ - ('black', 'Black'), - ('brown', 'Brown'), - ('green', 'Green'), - ('yellow', 'Yellow'), + ('black', _('Black')), + ('brown', _('Brown')), + ('green', _('Green')), + ('yellow', _('Yellow')), ]) objects = models.Manager() @@ -119,6 +125,8 @@ class DiaperChange(models.Model): class Meta: default_permissions = ('view', 'add', 'change', 'delete') ordering = ['-time'] + verbose_name = _('Diaper Change') + verbose_name_plural = _('Diaper Changes') def __str__(self): return 'Diaper Change' @@ -139,24 +147,28 @@ class DiaperChange(models.Model): # One or both of Wet and Solid is required. if not self.wet and not self.solid: raise ValidationError( - 'Wet and/or solid is required.', code='wet_or_solid') + _('Wet and/or solid is required.'), code='wet_or_solid') class Feeding(models.Model): model_name = 'feeding' child = models.ForeignKey( - 'Child', related_name='feeding', on_delete=models.CASCADE) + 'Child', + on_delete=models.CASCADE, + related_name='feeding', + verbose_name=_('Child') + ) start = models.DateTimeField(blank=False, null=False) end = models.DateTimeField(blank=False, null=False) duration = models.DurationField(null=True, editable=False) type = models.CharField(max_length=255, choices=[ - ('breast milk', 'Breast milk'), - ('formula', 'Formula'), + ('breast milk', _('Breast milk')), + ('formula', _('Formula')), ]) method = models.CharField(max_length=255, choices=[ - ('bottle', 'Bottle'), - ('left breast', 'Left breast'), - ('right breast', 'Right breast'), + ('bottle', _('Bottle')), + ('left breast', _('Left breast')), + ('right breast', _('Right breast')), ]) amount = models.FloatField(blank=True, null=True) @@ -165,6 +177,8 @@ class Feeding(models.Model): class Meta: default_permissions = ('view', 'add', 'change', 'delete') ordering = ['-start'] + verbose_name = _('Feeding') + verbose_name_plural = _('Feedings') def __str__(self): return 'Feeding' @@ -184,14 +198,18 @@ class Feeding(models.Model): if self.type == 'formula'and self.method != 'bottle': raise ValidationError( {'method': - 'Only "Bottle" method is allowed with "Formula" type.'}, + _('Only "Bottle" method is allowed with "Formula" type.')}, code='bottle_formula_mismatch') class Note(models.Model): model_name = 'note' child = models.ForeignKey( - 'Child', related_name='note', on_delete=models.CASCADE) + 'Child', + on_delete=models.CASCADE, + related_name='note', + verbose_name=_('Child') + ) note = models.TextField() time = models.DateTimeField(auto_now=True) @@ -200,6 +218,8 @@ class Note(models.Model): class Meta: default_permissions = ('view', 'add', 'change', 'delete') ordering = ['-time'] + verbose_name = _('Note') + verbose_name_plural = _('Notes') def __str__(self): return 'Note' @@ -214,7 +234,11 @@ class NapsManager(models.Manager): class Sleep(models.Model): model_name = 'sleep' child = models.ForeignKey( - 'Child', related_name='sleep', on_delete=models.CASCADE) + 'Child', + on_delete=models.CASCADE, + related_name='sleep', + verbose_name=_('Child') + ) start = models.DateTimeField(blank=False, null=False) end = models.DateTimeField(blank=False, null=False) duration = models.DurationField(null=True, editable=False) @@ -225,7 +249,8 @@ class Sleep(models.Model): class Meta: default_permissions = ('view', 'add', 'change', 'delete') ordering = ['-start'] - verbose_name_plural = 'Sleep' + verbose_name = _('Sleep') + verbose_name_plural = _('Sleep') def __str__(self): return 'Sleep' @@ -257,7 +282,7 @@ class Timer(models.Model): start = models.DateTimeField( default=timezone.now, blank=False, - verbose_name='Start Time' + verbose_name=_('Start Time') ) end = models.DateTimeField(blank=True, null=True, editable=False) duration = models.DurationField(null=True, editable=False) @@ -270,6 +295,8 @@ class Timer(models.Model): class Meta: default_permissions = ('view', 'add', 'change', 'delete') ordering = ['-active', '-start', '-end'] + verbose_name = _('Timer') + verbose_name_plural = _('Timers') def __str__(self): return self.name or 'Timer #{}'.format(self.id) @@ -315,7 +342,11 @@ class Timer(models.Model): class TummyTime(models.Model): model_name = 'tummytime' child = models.ForeignKey( - 'Child', related_name='tummy_time', on_delete=models.CASCADE) + 'Child', + on_delete=models.CASCADE, + related_name='tummy_time', + verbose_name=_('Child') + ) start = models.DateTimeField(blank=False, null=False) end = models.DateTimeField(blank=False, null=False) duration = models.DurationField(null=True, editable=False) @@ -326,6 +357,8 @@ class TummyTime(models.Model): class Meta: default_permissions = ('view', 'add', 'change', 'delete') ordering = ['-start'] + verbose_name = _('Tummy Time') + verbose_name_plural = _('Tummy Time') def __str__(self): return 'Tummy Time' @@ -346,7 +379,11 @@ class TummyTime(models.Model): class Weight(models.Model): model_name = 'weight' child = models.ForeignKey( - 'Child', related_name='weight', on_delete=models.CASCADE) + 'Child', + on_delete=models.CASCADE, + related_name='weight', + verbose_name=_('Child') + ) weight = models.FloatField(blank=False, null=False) date = models.DateField(blank=False, null=False) @@ -355,7 +392,8 @@ class Weight(models.Model): class Meta: default_permissions = ('view', 'add', 'change', 'delete') ordering = ['-date'] - verbose_name_plural = 'Weight' + verbose_name = _('Weight') + verbose_name_plural = _('Weight') def __str__(self): return 'Weight' diff --git a/core/templates/core/child_confirm_delete.html b/core/templates/core/child_confirm_delete.html index 07a14a27..a8357fb7 100644 --- a/core/templates/core/child_confirm_delete.html +++ b/core/templates/core/child_confirm_delete.html @@ -1,20 +1,22 @@ {% extends 'babybuddy/page.html' %} -{% load widget_tweaks %} +{% load i18n widget_tweaks %} -{% block title %}Delete a Child{% endblock %} +{% block title %}{% trans "Delete a Child" %}{% endblock %} {% block breadcrumbs %} - + - + {% endblock %} {% block content %}
{% csrf_token %} -

Are you sure you want to delete {{ object }}?

+ {% blocktrans %}

Are you sure you want to delete {{ object }}?

{% endblocktrans %}
- + {% if form.confirm_name.errors %} {{ form.confirm_name|add_class:"form-control is-invalid" }} {% else %} @@ -24,7 +26,7 @@
{{ form.confirm_name.errors.0 }}
{% endif %}
- - Cancel + + {% trans "Cancel" %}
{% endblock %} \ No newline at end of file diff --git a/core/templates/core/child_detail.html b/core/templates/core/child_detail.html index 6b0f8f2e..c68e3474 100644 --- a/core/templates/core/child_detail.html +++ b/core/templates/core/child_detail.html @@ -1,10 +1,10 @@ {% extends 'babybuddy/page.html' %} -{% load static thumbnail %} +{% load i18n static thumbnail %} {% block title %}{{ object }}{% endblock %} {% block breadcrumbs %} - + {% endblock %} @@ -20,8 +20,8 @@ {% endif %}
{{ object }}

- Born {{ object.birth_date }}
- Age {{ object.birth_date|timesince }} + {% trans "Born" %} {{ object.birth_date }}
+ {% trans "Age" %} {{ object.birth_date|timesince }}

{% include 'dashboard/child_button_group.html' %} @@ -31,16 +31,16 @@

{% if date_previous %} - + - Previous + {% trans "Previous" %} {% endif %} {{ date|date }} {% if date_next %} - + - Next + {% trans "Next" %} {% endif %}

diff --git a/core/templates/core/child_form.html b/core/templates/core/child_form.html index d53b0630..04bf3853 100644 --- a/core/templates/core/child_form.html +++ b/core/templates/core/child_form.html @@ -1,28 +1,29 @@ {% extends 'babybuddy/page.html' %} +{% load i18n %} {% block title %} {% if object %} {{ object }} {% else %} - Add a Child + {% trans "Add a Child" %} {% endif %} {% endblock %} {% block breadcrumbs %} - + {% if object %} - + {% else %} - + {% endif %} {% endblock %} {% block content %} {% if object %} -

Update {{ object }}

+ {% blocktrans %}

Update {{ object }}

{% endblocktrans %} {% else %} -

Add a Child

+

{% trans "Add a Child" %}

{% endif %} {% include 'babybuddy/form.html' %} {% endblock %} diff --git a/core/templates/core/child_list.html b/core/templates/core/child_list.html index 47b3730c..1036fe4b 100644 --- a/core/templates/core/child_list.html +++ b/core/templates/core/child_list.html @@ -1,10 +1,10 @@ {% extends 'babybuddy/page.html' %} -{% load widget_tweaks static thumbnail %} +{% load i18n static thumbnail widget_tweaks %} -{% block title %}Children{% endblock %} +{% block title %}{% trans "Children" %}{% endblock %} {% block breadcrumbs %} - + {% endblock %} {% block content %} @@ -15,10 +15,10 @@ - First Name - Last Name - Birth Date - Actions + {% trans "First Name" %} + {% trans "Last Name" %} + {% trans "Birth Date" %} + {% trans "Actions" %} @@ -38,7 +38,7 @@ {{ child.last_name }} {{ child.birth_date }} -
+
{% if perms.core.change_child %} @@ -57,7 +57,7 @@ {% empty %} - No children found. + {% trans "No children found." %} {% endfor %} @@ -67,7 +67,7 @@ {% if perms.core.add_child %} - Add a Child + {% trans "Add a Child" %} {% endif %} diff --git a/core/templates/core/diaperchange_confirm_delete.html b/core/templates/core/diaperchange_confirm_delete.html index 835b4053..8336fe55 100644 --- a/core/templates/core/diaperchange_confirm_delete.html +++ b/core/templates/core/diaperchange_confirm_delete.html @@ -1,18 +1,18 @@ {% extends 'babybuddy/page.html' %} -{% load widget_tweaks %} +{% load i18n widget_tweaks %} -{% block title %}Delete a Diaper Change{% endblock %} +{% block title %}{% trans "Delete a Diaper Change" %}{% endblock %} {% block breadcrumbs %} - - + + {% endblock %} {% block content %}
{% csrf_token %} -

Are you sure you want to delete {{ object }}?

- - Cancel + {% blocktrans %}

Are you sure you want to delete {{ object }}?

{% endblocktrans %} + + {% trans "Cancel" %}
{% endblock %} \ No newline at end of file diff --git a/core/templates/core/diaperchange_form.html b/core/templates/core/diaperchange_form.html index d515fd48..8f3dd0be 100644 --- a/core/templates/core/diaperchange_form.html +++ b/core/templates/core/diaperchange_form.html @@ -1,27 +1,28 @@ {% extends 'babybuddy/page.html' %} +{% load i18n %} {% block title %} {% if request.resolver_match.url_name == 'diaperchange-update' %} - Update a Diaper Change + {% trans "Update a Diaper Change" %} {% else %} - Add a Diaper Change + {% trans "Add a Diaper Change" %} {% endif %} {% endblock %} {% block breadcrumbs %} - + {% if object %} - + {% else %} - + {% endif %} {% endblock %} {% block content %} {% if object %} -

Update {{ object }}

+ {% blocktrans %}

Update {{ object }}

{% endblocktrans %} {% else %} -

Add a Diaper Change

+

{% trans "Add a Diaper Change" %}

{% endif %} {% include 'babybuddy/form.html' %} {% endblock %} diff --git a/core/templates/core/diaperchange_list.html b/core/templates/core/diaperchange_list.html index bc4cad91..1412219b 100644 --- a/core/templates/core/diaperchange_list.html +++ b/core/templates/core/diaperchange_list.html @@ -1,26 +1,25 @@ {% extends 'babybuddy/page.html' %} -{% load widget_tweaks %} -{% load bootstrap %} +{% load bootstrap i18n widget_tweaks %} -{% block title %}Diaper Changes{% endblock %} +{% block title %}{% trans "Diaper Changes" %}{% endblock %} {% block breadcrumbs %} - + {% endblock %} {% block content %} -

Diaper Changes

+

{% trans "Diaper Changes" %}

{% include 'babybuddy/filter.html' %}
- - - - - - + + + + + + @@ -32,7 +31,7 @@ {% empty %} - + {% endfor %} @@ -61,7 +60,7 @@ {% if perms.core.add_diaperchange %} - Add a Change + {% trans "Add a Change" %} {% endif %} diff --git a/core/templates/core/feeding_confirm_delete.html b/core/templates/core/feeding_confirm_delete.html index 5d294ec1..8d5a0b8f 100644 --- a/core/templates/core/feeding_confirm_delete.html +++ b/core/templates/core/feeding_confirm_delete.html @@ -1,18 +1,18 @@ {% extends 'babybuddy/page.html' %} -{% load widget_tweaks %} +{% load i18n widget_tweaks %} -{% block title %}Delete a Feeding{% endblock %} +{% block title %}{% trans "Delete a Feeding" %}{% endblock %} {% block breadcrumbs %} - - + + {% endblock %} {% block content %} {% csrf_token %} -

Are you sure you want to delete {{ object }}?

- - Cancel + {% blocktrans %}

Are you sure you want to delete {{ object }}?

{% endblocktrans %} + + {% trans "Cancel" %} {% endblock %} \ No newline at end of file diff --git a/core/templates/core/feeding_form.html b/core/templates/core/feeding_form.html index b8c95d39..734f9895 100644 --- a/core/templates/core/feeding_form.html +++ b/core/templates/core/feeding_form.html @@ -1,27 +1,28 @@ {% extends 'babybuddy/page.html' %} +{% load i18n %} {% block title %} {% if request.resolver_match.url_name == 'feeding-update' %} - Update a Feeding + {% trans "Update a Feeding" %} {% else %} - Add a Feeding + {% trans "Add a Feeding" %} {% endif %} {% endblock %} {% block breadcrumbs %} - + {% if object %} - + {% else %} - + {% endif %} {% endblock %} {% block content %} {% if object %} -

Update {{ object }}

+ {% blocktrans %}

Update {{ object }}

{% endblocktrans %} {% else %} -

Add a Feeding

+

{% trans "Add a Feeding" %}

{% endif %} {% include 'babybuddy/form.html' %} {% endblock %} diff --git a/core/templates/core/feeding_list.html b/core/templates/core/feeding_list.html index 205df467..57934fef 100644 --- a/core/templates/core/feeding_list.html +++ b/core/templates/core/feeding_list.html @@ -1,11 +1,10 @@ {% extends 'babybuddy/page.html' %} -{% load widget_tweaks %} -{% load duration %} +{% load duration i18n widget_tweaks %} -{% block title %}Feedings{% endblock %} +{% block title %}{% trans "Feedings" %}{% endblock %} {% block breadcrumbs %} - + {% endblock %} {% block content %} @@ -15,13 +14,14 @@
ChildWetSolidColorTimeActions{% trans "Child" %}{% trans "Wet" %}{% trans "Solid" %}{% trans "Color" %}{% trans "Time" %}{% trans "Actions" %}
{{ change.color }} {{ change.time|date:'n/j/y G:i' }} -
+
{% if perms.core.change_diaperchange %} @@ -51,7 +50,7 @@
No diaper changes found.{% trans "No diaper changes found." %}
- - - - - - - + + + + {% comment %}Abbreviation of "Amount"{% endcomment %} + + + + @@ -38,7 +38,7 @@ {% empty %} - + {% endfor %} @@ -67,7 +67,7 @@ {% if perms.core.add_feeding %} - Add a Feeding + {% trans "Add a Feeding" %} {% endif %} diff --git a/core/templates/core/note_confirm_delete.html b/core/templates/core/note_confirm_delete.html index 6fc62977..a70ffa02 100644 --- a/core/templates/core/note_confirm_delete.html +++ b/core/templates/core/note_confirm_delete.html @@ -1,18 +1,18 @@ {% extends 'babybuddy/page.html' %} -{% load widget_tweaks %} +{% load i18n widget_tweaks %} -{% block title %}Delete a Note{% endblock %} +{% block title %}{% trans "Delete a Note" %}{% endblock %} {% block breadcrumbs %} - - + + {% endblock %} {% block content %} {% csrf_token %} -

Are you sure you want to delete {{ object }}?

- - Cancel + {% blocktrans %}

Are you sure you want to delete {{ object }}?

{% endblocktrans %} + + {% trans "Cancel" %} {% endblock %} \ No newline at end of file diff --git a/core/templates/core/note_form.html b/core/templates/core/note_form.html index e0142f89..1718fa3f 100644 --- a/core/templates/core/note_form.html +++ b/core/templates/core/note_form.html @@ -1,27 +1,28 @@ {% extends 'babybuddy/page.html' %} +{% load i18n %} {% block title %} {% if request.resolver_match.url_name == 'note-update' %} - Update a Note + {% trans "Update a Note" %} {% else %} - Add a Note + {% trans "Add a Note" %} {% endif %} {% endblock %} {% block breadcrumbs %} - + {% if object %} - + {% else %} - + {% endif %} {% endblock %} {% block content %} {% if object %} -

Update {{ object }}

+ {% blocktrans %}

Update {{ object }}

{% endblocktrans %} {% else %} -

Add a Note

+

{% trans "Add a Note" %}

{% endif %} {% include 'babybuddy/form.html' %} {% endblock %} \ No newline at end of file diff --git a/core/templates/core/note_list.html b/core/templates/core/note_list.html index 6ccabe7d..b0dc75e2 100644 --- a/core/templates/core/note_list.html +++ b/core/templates/core/note_list.html @@ -1,10 +1,10 @@ {% extends 'babybuddy/page.html' %} -{% load widget_tweaks %} +{% load i18n widget_tweaks %} -{% block title %}Notes{% endblock %} +{% block title %}{% trans "Notes" %}{% endblock %} {% block breadcrumbs %} - + {% endblock %} {% block content %} @@ -14,10 +14,10 @@
ChildMethodTypeAmt.DurationDateActions{% trans "Child" %}{% trans "Method" %}{% trans "Type" %}{% trans "Amt." %}{% trans "Duration" %}{% trans "Date" %}{% trans "Actions" %}
{{ feeding.duration|duration_string }} {{ feeding.start|date:'n/j/y G:i' }} -
+
{% if perms.core.change_feeding %} @@ -57,7 +57,7 @@
No feedings found.{% trans "No feedings found." %}
- - - - + + + + @@ -27,7 +27,7 @@ {% empty %} - + {% endfor %} @@ -56,7 +56,7 @@ {% if perms.core.add_note %} - Add a Note + {% trans "Add a Note" %} {% endif %} diff --git a/core/templates/core/sleep_confirm_delete.html b/core/templates/core/sleep_confirm_delete.html index 1756fdcd..56c265e4 100644 --- a/core/templates/core/sleep_confirm_delete.html +++ b/core/templates/core/sleep_confirm_delete.html @@ -1,18 +1,18 @@ {% extends 'babybuddy/page.html' %} -{% load widget_tweaks %} +{% load i18n widget_tweaks %} -{% block title %}Delete a Sleep Entry{% endblock %} +{% block title %}{% trans "Delete a Sleep Entry" %}{% endblock %} {% block breadcrumbs %} - - + + {% endblock %} {% block content %} {% csrf_token %} -

Are you sure you want to delete {{ object }}?

- - Cancel + {% blocktrans %}

Are you sure you want to delete {{ object }}?

{% endblocktrans %} + + {% trans "Cancel" %} {% endblock %} \ No newline at end of file diff --git a/core/templates/core/sleep_form.html b/core/templates/core/sleep_form.html index 9ec3f9dc..ec09437f 100644 --- a/core/templates/core/sleep_form.html +++ b/core/templates/core/sleep_form.html @@ -1,27 +1,28 @@ {% extends 'babybuddy/page.html' %} +{% load i18n %} {% block title %} {% if request.resolver_match.url_name == 'sleep-update' %} - Update a Sleep Entry + {% trans "Update a Sleep Entry" %} {% else %} - Add a Sleep Entry + {% trans "Add a Sleep Entry" %} {% endif %} {% endblock %} {% block breadcrumbs %} - + {% if object %} - + {% else %} - + {% endif %} {% endblock %} {% block content %} {% if object %} -

Update {{ object }}

+ {% blocktrans %}

Update {{ object }}

{% endblocktrans %} {% else %} -

Add a Sleep Entry

+

{% trans "Add a Sleep Entry" %}

{% endif %} {% include 'babybuddy/form.html' %} {% endblock %} diff --git a/core/templates/core/sleep_list.html b/core/templates/core/sleep_list.html index a25fa28d..aee2df5e 100644 --- a/core/templates/core/sleep_list.html +++ b/core/templates/core/sleep_list.html @@ -1,10 +1,10 @@ {% extends 'babybuddy/page.html' %} -{% load bootstrap duration widget_tweaks %} +{% load bootstrap duration i18n widget_tweaks %} -{% block title %}Sleep{% endblock %} +{% block title %}{% trans "Sleep" %}{% endblock %} {% block breadcrumbs %} - + {% endblock %} {% block content %} @@ -14,12 +14,12 @@
ChildNoteTimeActions{% trans "Child" %}{% trans "Note" %}{% trans "Time" %}{% trans "Actions" %}
{{ note.note }} {{ note.time }} -
+
{% if perms.core.change_note %} @@ -46,7 +46,7 @@
No notes found.{% trans "No notes found." %}
- - - - - - + + + + + + @@ -31,7 +31,7 @@ {% empty %} - + {% endfor %} @@ -60,7 +60,7 @@ {% if perms.core.add_sleep %} - Add a Sleep Entry + {% trans "Add a Sleep Entry" %} {% endif %} diff --git a/core/templates/core/timer_confirm_delete.html b/core/templates/core/timer_confirm_delete.html index 54e56223..853effb8 100644 --- a/core/templates/core/timer_confirm_delete.html +++ b/core/templates/core/timer_confirm_delete.html @@ -1,19 +1,19 @@ {% extends 'babybuddy/page.html' %} -{% load widget_tweaks %} +{% load i18n widget_tweaks %} -{% block title %}Delete {{ object }}{% endblock %} +{% block title %}{% blocktrans %}Delete {{ object }}{% endblocktrans %}{% endblock %} {% block breadcrumbs %} - + - + {% endblock %} {% block content %} {% csrf_token %} -

Are you sure you want to delete {{ object }}?

- - Cancel + {% blocktrans %}

Are you sure you want to delete {{ object }}?

{% endblocktrans %} + + {% trans "Cancel" %} {% endblock %} \ No newline at end of file diff --git a/core/templates/core/timer_detail.html b/core/templates/core/timer_detail.html index 65a0b9f5..88d11bd8 100644 --- a/core/templates/core/timer_detail.html +++ b/core/templates/core/timer_detail.html @@ -1,10 +1,10 @@ {% extends 'babybuddy/page.html' %} -{% load duration timers %} +{% load duration i18n timers %} {% block title %}{{ object }}{% endblock %} {% block breadcrumbs %} - + {% endblock %} @@ -17,34 +17,40 @@ {{ object.duration|seconds }}s

- Started {{ object.start }} + {% trans "Started" %} {{ object.start }} {% if not object.active %} - / Stopped {{ object.end }} + / {% trans "Stopped" %} {{ object.end }} {% endif %}

- {{ timer }} created by {{ object.user }} + {% blocktrans %}{{ timer }} created by {{ object.user }}{% endblocktrans %}

{% if perms.core.add_feeding %} Feeding + role="button"> + {% trans "Feeding" %} + {% endif %} {% if perms.core.add_sleep %} Sleep + role="button"> + {% trans "Sleep" %} + {% endif %} {% if perms.core.add_tummytime %} Tummy Time + role="button"> + {% trans "Tummy Time" %} + {% endif %} -
+
{% if perms.core.delete_timer %} Timers + {% if object %} - + {% else %} - + {% endif %} {% endblock %} {% block content %} {% if object %} -

Update {{ object }}

+ {% blocktrans %}

Update {{ object }}

{% endblocktrans %} {% else %} -

Start Timer

+

{% trans "Start Timer" %}

{% endif %} {% include 'babybuddy/form.html' %} {% endblock %} diff --git a/core/templates/core/timer_list.html b/core/templates/core/timer_list.html index 6bb1afd2..75ec6107 100644 --- a/core/templates/core/timer_list.html +++ b/core/templates/core/timer_list.html @@ -1,10 +1,10 @@ {% extends 'babybuddy/page.html' %} -{% load bootstrap duration widget_tweaks %} +{% load bootstrap duration i18n widget_tweaks %} -{% block title %}Timers{% endblock %} +{% block title %}{% trans "Timers" %}{% endblock %} {% block breadcrumbs %} - + {% endblock %} {% block content %} @@ -14,12 +14,12 @@
ChildDurationStartEndNapActions{% trans "Child" %}{% trans "Duration" %}{% trans "Start" %}{% trans "End" %}{% trans "Nap" %}{% trans "Actions" %}
{{ sleep.end|date:'n/j/y G:i' }} {{ sleep.nap|bool_icon }} -
+
{% if perms.core.change_sleep %} @@ -50,7 +50,7 @@
No sleep entries found.{% trans "No sleep entries found." %}
- - - - - - + + + + + + @@ -34,7 +34,7 @@ {% empty %} - + {% endfor %} diff --git a/core/templates/core/timer_nav.html b/core/templates/core/timer_nav.html index 92085515..75bed9d6 100644 --- a/core/templates/core/timer_nav.html +++ b/core/templates/core/timer_nav.html @@ -1,30 +1,34 @@ +{% load i18n %} + - + + {% endblock %} {% block content %} {% csrf_token %} -

Are you sure you want to delete {{ object }}?

- - Cancel + {% blocktrans %}

Are you sure you want to delete {{ object }}?

{% endblocktrans %} + + {% trans "Cancel" %} {% endblock %} \ No newline at end of file diff --git a/core/templates/core/tummytime_form.html b/core/templates/core/tummytime_form.html index 9d05b1a5..63bf927e 100644 --- a/core/templates/core/tummytime_form.html +++ b/core/templates/core/tummytime_form.html @@ -1,27 +1,28 @@ {% extends 'babybuddy/page.html' %} +{% load i18n %} {% block title %} {% if request.resolver_match.url_name == 'tummytime-update' %} - Update a Tummy Time Entry + {% trans "Update a Tummy Time Entry" %} {% else %} - Add a Tummy Time Entry + {% trans "Add a Tummy Time Entry" %} {% endif %} {% endblock %} {% block breadcrumbs %} - + {% if object %} - + {% else %} - + {% endif %} {% endblock %} {% block content %} {% if object %} -

Update {{ object }}

+ {% blocktrans %}

Update {{ object }}

{% endblocktrans %} {% else %} -

Add a Tummy Time Entry

+

{% trans "Add a Tummy Time Entry" %}

{% endif %} {% include 'babybuddy/form.html' %} {% endblock %} diff --git a/core/templates/core/tummytime_list.html b/core/templates/core/tummytime_list.html index dab1bc57..e67dd449 100644 --- a/core/templates/core/tummytime_list.html +++ b/core/templates/core/tummytime_list.html @@ -1,11 +1,10 @@ {% extends 'babybuddy/page.html' %} -{% load widget_tweaks %} -{% load duration %} +{% load duration i18n widget_tweaks %} -{% block title %}Tummy Time{% endblock %} +{% block title %}{% trans "Tummy Time" %}{% endblock %} {% block breadcrumbs %} - + {% endblock %} {% block content %} @@ -15,12 +14,12 @@
NameStartDurationEndActiveUser{% trans "Name" %}{% trans "Start" %}{% trans "Duration" %}{% trans "End" %}{% trans "Active" %}{% trans "User" %}
No timer entries found.{% trans "No timer entries found." %}
- - - - - - + + + + + + @@ -32,7 +31,7 @@ {% empty %} - + {% endfor %} @@ -61,7 +60,7 @@ {% if perms.core.add_tummytime %} - Add a Tummy Time Entry + {% trans "Add a Tummy Time Entry" %} {% endif %} {% endblock %} \ No newline at end of file diff --git a/core/templates/core/weight_confirm_delete.html b/core/templates/core/weight_confirm_delete.html index 839a58a1..40cb1759 100644 --- a/core/templates/core/weight_confirm_delete.html +++ b/core/templates/core/weight_confirm_delete.html @@ -1,18 +1,18 @@ {% extends 'babybuddy/page.html' %} -{% load widget_tweaks %} +{% load i18n widget_tweaks %} -{% block title %}Delete a Weight Entry{% endblock %} +{% block title %}{% trans "Delete a Weight Entry" %}{% endblock %} {% block breadcrumbs %} - - + + {% endblock %} {% block content %} {% csrf_token %} -

Are you sure you want to delete {{ object }}?

- - Cancel + {% blocktrans %}

Are you sure you want to delete {{ object }}?

{% endblocktrans %} + + {% trans "Cancel" %} {% endblock %} \ No newline at end of file diff --git a/core/templates/core/weight_form.html b/core/templates/core/weight_form.html index 1575e5e3..40d567d5 100644 --- a/core/templates/core/weight_form.html +++ b/core/templates/core/weight_form.html @@ -1,27 +1,28 @@ {% extends 'babybuddy/page.html' %} +{% load i18n %} {% block title %} {% if object %} {{ object }} {% else %} - Add a Weight Entry + {% trans "Add a Weight Entry" %} {% endif %} {% endblock %} {% block breadcrumbs %} - + {% if object %} - + {% else %} - + {% endif %} {% endblock %} {% block content %} {% if object %} -

Update {{ object }}

+ {% blocktrans %}

Update {{ object }}

{% endblocktrans %} {% else %} -

Add a Weight Entry

+

{% trans "Add a Weight Entry" %}

{% endif %} {% include 'babybuddy/form.html' %} {% endblock %} diff --git a/core/templates/core/weight_list.html b/core/templates/core/weight_list.html index f7c6689d..d4f77ba2 100644 --- a/core/templates/core/weight_list.html +++ b/core/templates/core/weight_list.html @@ -1,10 +1,10 @@ {% extends 'babybuddy/page.html' %} -{% load widget_tweaks %} +{% load i18n widget_tweaks %} -{% block title %}Weight{% endblock %} +{% block title %}{% trans "Weight" %}{% endblock %} {% block breadcrumbs %} - + {% endblock %} {% block content %} @@ -14,10 +14,10 @@
ChildDurationStartEndMilestoneActions{% trans "Child" %}{% trans "Duration" %}{% trans "Start" %}{% trans "End" %}{% trans "Milestone" %}{% trans "Actions" %}
{{ tummytime.end|date:'n/j/y G:i' }} {{ tummytime.milestone }} -
+
{% if perms.core.change_tummytime %} @@ -51,7 +50,7 @@
No tummy time entries found.{% trans "No tummy time entries found." %}
- - - - + + + + @@ -27,7 +27,7 @@ {% empty %} - + {% endfor %} @@ -56,7 +56,7 @@ {% if perms.core.add_weight %} - Add a Weight Entry + {% trans "Add a Weight Entry" %} {% endif %} diff --git a/core/views.py b/core/views.py index cc4b2dfb..783f1116 100644 --- a/core/views.py +++ b/core/views.py @@ -3,6 +3,7 @@ from django.contrib import messages from django.contrib.messages.views import SuccessMessageMixin from django.urls import reverse, reverse_lazy from django.utils import timezone +from django.utils.translation import gettext as _ from django.views.generic.base import RedirectView from django.views.generic.detail import DetailView from django.views.generic.edit import CreateView, UpdateView, DeleteView @@ -16,9 +17,9 @@ class CoreAddView(PermissionRequired403Mixin, SuccessMessageMixin, CreateView): def get_success_message(self, cleaned_data): cleaned_data['model'] = self.model._meta.verbose_name.title() if 'child' in cleaned_data: - self.success_message = '%(model)s entry for %(child)s added!' + self.success_message = _('%(model)s entry for %(child)s added!') else: - self.success_message = '%(model)s entry added!' + self.success_message = _('%(model)s entry added!') return self.success_message % cleaned_data @@ -27,9 +28,9 @@ class CoreUpdateView(PermissionRequired403Mixin, SuccessMessageMixin, def get_success_message(self, cleaned_data): cleaned_data['model'] = self.model._meta.verbose_name.title() if 'child' in cleaned_data: - self.success_message = '%(model)s entry for %(child)s updated.' + self.success_message = _('%(model)s entry for %(child)s updated.') else: - self.success_message = '%(model)s entry updated.' + self.success_message = _('%(model)s entry updated.') return self.success_message % cleaned_data @@ -58,7 +59,7 @@ class ChildAdd(CoreAddView): permission_required = ('core.add_child',) form_class = forms.ChildForm success_url = reverse_lazy('core:child-list') - success_message = '%(first_name)s %(last_name)s added!' + success_message = _('%(first_name)s %(last_name)s added!') class ChildDetail(PermissionRequired403Mixin, DetailView): @@ -286,7 +287,7 @@ class TimerRestart(PermissionRequired403Mixin, RedirectView): class TimerStop(PermissionRequired403Mixin, SuccessMessageMixin, RedirectView): permission_required = ('core.change_timer',) - success_message = '%(timer)s stopped.' + success_message = _('%(timer)s stopped.') def get(self, request, *args, **kwargs): instance = models.Timer.objects.get(id=kwargs['pk'])
ChildWeightDateActions{% trans "Child" %}{% trans "Weight" %}{% trans "Date" %}{% trans "Actions" %}
{{ object.weight }} {{ object.date }} -
+
{% if perms.core.change_weight %} @@ -46,7 +46,7 @@
No weight entries found.{% trans "No weight entries found." %}