From c36451fc8e8d8f9c2f31ff3e3ad26ecc63ccbedb Mon Sep 17 00:00:00 2001 From: "Christopher C. Wells" Date: Sat, 13 Apr 2019 21:50:35 -0700 Subject: [PATCH] Add translateable strings support in babybuddy app. --- babybuddy/admin.py | 6 +- babybuddy/models.py | 25 +++-- babybuddy/templates/403.html | 10 +- babybuddy/templates/babybuddy/base.html | 4 +- babybuddy/templates/babybuddy/filter.html | 8 +- babybuddy/templates/babybuddy/form.html | 4 +- babybuddy/templates/babybuddy/messages.html | 6 +- .../templates/babybuddy/nav-dropdown.html | 106 ++++++++++++------ babybuddy/templates/babybuddy/paginator.html | 6 +- .../babybuddy/user_confirm_delete.html | 12 +- babybuddy/templates/babybuddy/user_form.html | 13 ++- babybuddy/templates/babybuddy/user_list.html | 24 ++-- .../babybuddy/user_password_form.html | 10 +- .../babybuddy/user_settings_form.html | 26 ++--- babybuddy/templates/babybuddy/welcome.html | 26 ++--- babybuddy/templates/registration/login.html | 6 +- .../registration/password_reset_complete.html | 7 +- .../registration/password_reset_confirm.html | 13 +-- .../registration/password_reset_done.html | 7 +- .../registration/password_reset_form.html | 12 +- babybuddy/views.py | 11 +- 21 files changed, 193 insertions(+), 149 deletions(-) diff --git a/babybuddy/admin.py b/babybuddy/admin.py index ee7e4fd0..0eb69815 100644 --- a/babybuddy/admin.py +++ b/babybuddy/admin.py @@ -2,16 +2,18 @@ from django.contrib import admin from django.contrib.auth.admin import UserAdmin as BaseUserAdmin from django.contrib.auth.models import User +from django.utils.translation import gettext_lazy as _ from babybuddy import models class SettingsInline(admin.StackedInline): model = models.Settings - verbose_name_plural = 'Settings' + verbose_name = _('Settings') + verbose_name_plural = _('Settings') can_delete = False fieldsets = ( - ('Dashboard', { + (_('Dashboard'), { 'fields': ('dashboard_refresh_rate',) }), ) diff --git a/babybuddy/models.py b/babybuddy/models.py index 1c36ed9b..070db1a9 100644 --- a/babybuddy/models.py +++ b/babybuddy/models.py @@ -4,6 +4,7 @@ from django.db import models from django.db.models.signals import post_save from django.dispatch import receiver from django.utils.timezone import timedelta +from django.utils.translation import gettext_lazy as _ from rest_framework.authtoken.models import Token @@ -11,22 +12,22 @@ from rest_framework.authtoken.models import Token class Settings(models.Model): user = models.OneToOneField(User, on_delete=models.CASCADE) dashboard_refresh_rate = models.DurationField( - verbose_name='Refresh rate', - help_text='This setting will only be used when a browser does not ' - 'support refresh on focus.', + verbose_name=_('Refresh rate'), + help_text=_('This setting will only be used when a browser does not ' + 'support refresh on focus.'), blank=True, null=True, default=timedelta(minutes=1), choices=[ - (None, 'disabled'), - (timedelta(minutes=1), '1 min.'), - (timedelta(minutes=2), '2 min.'), - (timedelta(minutes=3), '3 min.'), - (timedelta(minutes=4), '4 min.'), - (timedelta(minutes=5), '5 min.'), - (timedelta(minutes=10), '10 min.'), - (timedelta(minutes=15), '15 min.'), - (timedelta(minutes=30), '30 min.'), + (None, _('disabled')), + (timedelta(minutes=1), _('1 min.')), + (timedelta(minutes=2), _('2 min.')), + (timedelta(minutes=3), _('3 min.')), + (timedelta(minutes=4), _('4 min.')), + (timedelta(minutes=5), _('5 min.')), + (timedelta(minutes=10), _('10 min.')), + (timedelta(minutes=15), _('15 min.')), + (timedelta(minutes=30), _('30 min.')), ]) def __str__(self): diff --git a/babybuddy/templates/403.html b/babybuddy/templates/403.html index 0eb0d4d5..530950a0 100644 --- a/babybuddy/templates/403.html +++ b/babybuddy/templates/403.html @@ -1,15 +1,15 @@ {% extends 'babybuddy/page.html' %} -{% load widget_tweaks %} +{% load i18n widget_tweaks %} -{% block title %}403 Permission Denied{% endblock %} +{% block title %}403 {% trans "Permission Denied" %}{% endblock %} {% block breadcrumbs %} - + {% endblock %} {% block content %} {% endblock %} \ No newline at end of file diff --git a/babybuddy/templates/babybuddy/base.html b/babybuddy/templates/babybuddy/base.html index 04878c35..a17188aa 100644 --- a/babybuddy/templates/babybuddy/base.html +++ b/babybuddy/templates/babybuddy/base.html @@ -1,4 +1,4 @@ -{% load static %} +{% load i18n static %} @@ -31,7 +31,7 @@ {% block breadcrumb_nav %} diff --git a/babybuddy/templates/babybuddy/filter.html b/babybuddy/templates/babybuddy/filter.html index 0379d6a9..84765a40 100644 --- a/babybuddy/templates/babybuddy/filter.html +++ b/babybuddy/templates/babybuddy/filter.html @@ -1,4 +1,4 @@ -{% load widget_tweaks %} +{% load i18n widget_tweaks %}
@@ -15,8 +15,8 @@
{% endfor %}
- - Reset + + {% trans "Reset" %}
@@ -29,6 +29,6 @@ role="button" aria-expanded="false" aria-controls="filter_form"> - Filters + {% trans "Filters" %}

diff --git a/babybuddy/templates/babybuddy/form.html b/babybuddy/templates/babybuddy/form.html index 83dc2555..25bf20dc 100644 --- a/babybuddy/templates/babybuddy/form.html +++ b/babybuddy/templates/babybuddy/form.html @@ -1,4 +1,4 @@ -{% load widget_tweaks %} +{% load i18n widget_tweaks %}
@@ -8,6 +8,6 @@ {% include 'babybuddy/form_field.html' %}
{% endfor %} - +
diff --git a/babybuddy/templates/babybuddy/messages.html b/babybuddy/templates/babybuddy/messages.html index 45627ffe..c751a753 100644 --- a/babybuddy/templates/babybuddy/messages.html +++ b/babybuddy/templates/babybuddy/messages.html @@ -1,3 +1,5 @@ +{% load i18n %} + {% block messages %} {% if messages %} {% for message in messages %} @@ -13,12 +15,12 @@ {% if form.non_field_errors %} {% for error in form.non_field_errors %} {% endfor %} {% elif form.errors %} {% endif %} {% endif %} diff --git a/babybuddy/templates/babybuddy/nav-dropdown.html b/babybuddy/templates/babybuddy/nav-dropdown.html index 43d4013b..1bace63c 100644 --- a/babybuddy/templates/babybuddy/nav-dropdown.html +++ b/babybuddy/templates/babybuddy/nav-dropdown.html @@ -1,5 +1,5 @@ {% extends 'babybuddy/base.html' %} -{% load babybuddy_tags static timers %} +{% load babybuddy_tags i18n static timers %} {% block nav %}