From 8ed0e9117a794eebe375be79e1d7597098e945e3 Mon Sep 17 00:00:00 2001 From: "Christopher C. Wells" Date: Sun, 14 Apr 2019 13:32:46 -0700 Subject: [PATCH] Add translatable strings support to reports app. --- reports/graphs/diaperchange_lifetimes.py | 8 +++++--- reports/graphs/diaperchange_types.py | 13 +++++++------ reports/graphs/feeding_duration.py | 13 +++++++------ reports/graphs/sleep_pattern.py | 7 ++++--- reports/graphs/sleep_totals.py | 9 +++++---- reports/graphs/weight_weight.py | 10 ++++++---- .../templates/reports/diaperchange_lifetimes.html | 5 +++-- reports/templates/reports/diaperchange_types.html | 5 +++-- reports/templates/reports/feeding_duration.html | 5 +++-- reports/templates/reports/report_base.html | 8 ++++---- reports/templates/reports/sleep_pattern.html | 5 +++-- reports/templates/reports/sleep_totals.html | 5 +++-- reports/templates/reports/weight_change.html | 5 +++-- 13 files changed, 56 insertions(+), 42 deletions(-) diff --git a/reports/graphs/diaperchange_lifetimes.py b/reports/graphs/diaperchange_lifetimes.py index 357185bb..00c34d66 100644 --- a/reports/graphs/diaperchange_lifetimes.py +++ b/reports/graphs/diaperchange_lifetimes.py @@ -1,4 +1,6 @@ # -*- coding: utf-8 -*- +from django.utils.translation import gettext as _ + import plotly.offline as plotly import plotly.graph_objs as go @@ -22,7 +24,7 @@ def diaperchange_lifetimes(changes): trace = go.Box( y=[round(d.seconds/3600, 2) for d in durations], - name='Changes', + name=_('Changes'), jitter=0.3, pointpos=-1.8, boxpoints='all' @@ -30,8 +32,8 @@ def diaperchange_lifetimes(changes): layout_args = utils.default_graph_layout_options() layout_args['height'] = 800 - layout_args['title'] = 'Diaper Lifetimes' - layout_args['yaxis']['title'] = 'Time between changes (hours)' + layout_args['title'] = _('Diaper Lifetimes') + layout_args['yaxis']['title'] = _('Time between changes (hours)') layout_args['yaxis']['zeroline'] = False layout_args['yaxis']['dtick'] = 1 diff --git a/reports/graphs/diaperchange_types.py b/reports/graphs/diaperchange_types.py index 0ce7d0b7..f23a5ccd 100644 --- a/reports/graphs/diaperchange_types.py +++ b/reports/graphs/diaperchange_types.py @@ -1,6 +1,7 @@ # -*- coding: utf-8 -*- from django.db.models import Count, Case, When from django.db.models.functions import TruncDate +from django.utils.translation import gettext as _ import plotly.offline as plotly import plotly.graph_objs as go @@ -23,28 +24,28 @@ def diaperchange_types(changes): solid_trace = go.Scatter( mode='markers', - name='Solid', + name=_('Solid'), x=list(changes.values_list('date', flat=True)), y=list(changes.values_list('solid_count', flat=True)), ) wet_trace = go.Scatter( mode='markers', - name='Wet', + name=_('Wet'), x=list(changes.values_list('date', flat=True)), y=list(changes.values_list('wet_count', flat=True)) ) total_trace = go.Scatter( - name='Total', + name=_('Total'), x=list(changes.values_list('date', flat=True)), y=list(changes.values_list('total', flat=True)) ) layout_args = utils.default_graph_layout_options() layout_args['barmode'] = 'stack' - layout_args['title'] = 'Diaper Change Types' - layout_args['xaxis']['title'] = 'Date' + layout_args['title'] = _('Diaper Change Types') + layout_args['xaxis']['title'] = _('Date') layout_args['xaxis']['rangeselector'] = utils.rangeselector_date() - layout_args['yaxis']['title'] = 'Number of changes' + layout_args['yaxis']['title'] = _('Number of changes') fig = go.Figure({ 'data': [solid_trace, wet_trace, total_trace], diff --git a/reports/graphs/feeding_duration.py b/reports/graphs/feeding_duration.py index a605a514..5128eb42 100644 --- a/reports/graphs/feeding_duration.py +++ b/reports/graphs/feeding_duration.py @@ -1,6 +1,7 @@ # -*- coding: utf-8 -*- from django.db.models import Count, Sum from django.db.models.functions import TruncDate +from django.utils.translation import gettext as _ import plotly.offline as plotly import plotly.graph_objs as go @@ -32,7 +33,7 @@ def feeding_duration(instances): averages.append(total['sum']/total['count']) trace_avg = go.Scatter( - name='Average duration', + name=_('Average duration'), line=dict(shape='spline'), x=list(totals.values_list('date', flat=True)), y=[td.seconds/60 for td in averages], @@ -40,7 +41,7 @@ def feeding_duration(instances): text=[_duration_string_ms(td) for td in averages] ) trace_count = go.Scatter( - name='Total feedings', + name=_('Total feedings'), mode='markers', x=list(totals.values_list('date', flat=True)), y=list(totals.values_list('count', flat=True)), @@ -49,12 +50,12 @@ def feeding_duration(instances): ) layout_args = utils.default_graph_layout_options() - layout_args['title'] = 'Average Feeding Durations' - layout_args['xaxis']['title'] = 'Date' + layout_args['title'] = _('Average Feeding Durations') + layout_args['xaxis']['title'] = _('Date') layout_args['xaxis']['rangeselector'] = utils.rangeselector_date() - layout_args['yaxis']['title'] = 'Average duration (minutes)' + layout_args['yaxis']['title'] = _('Average duration (minutes)') layout_args['yaxis2'] = dict(layout_args['yaxis']) - layout_args['yaxis2']['title'] = 'Number of feedings' + layout_args['yaxis2']['title'] = _('Number of feedings') layout_args['yaxis2']['overlaying'] = 'y' layout_args['yaxis2']['side'] = 'right' diff --git a/reports/graphs/sleep_pattern.py b/reports/graphs/sleep_pattern.py index abba7460..3c00c0bd 100644 --- a/reports/graphs/sleep_pattern.py +++ b/reports/graphs/sleep_pattern.py @@ -2,6 +2,7 @@ from collections import OrderedDict from django.utils import timezone +from django.utils.translation import gettext as _ import pandas as pd import plotly.offline as plotly @@ -124,10 +125,10 @@ def sleep_pattern(instances): layout_args['barmode'] = 'stack' layout_args['hovermode'] = 'closest' - layout_args['title'] = 'Sleep Pattern' + layout_args['title'] = _('Sleep Pattern') layout_args['height'] = 800 - layout_args['xaxis']['title'] = 'Date' + layout_args['xaxis']['title'] = _('Date') layout_args['xaxis']['tickangle'] = -65 layout_args['xaxis']['rangeselector'] = utils.rangeselector_date() @@ -137,7 +138,7 @@ def sleep_pattern(instances): for i in range(30, 60*24, 30): ticks[i] = (start + timezone.timedelta(minutes=i)).strftime('%I:%M %p') - layout_args['yaxis']['title'] = 'Time of day' + layout_args['yaxis']['title'] = _('Time of day') layout_args['yaxis']['rangemode'] = 'tozero' layout_args['yaxis']['tickmode'] = 'array' layout_args['yaxis']['tickvals'] = list(ticks.keys()) diff --git a/reports/graphs/sleep_totals.py b/reports/graphs/sleep_totals.py index fdfabb37..0e5f3a37 100644 --- a/reports/graphs/sleep_totals.py +++ b/reports/graphs/sleep_totals.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- from django.utils import timezone +from django.utils.translation import gettext as _ import plotly.offline as plotly import plotly.graph_objs as go @@ -36,7 +37,7 @@ def sleep_totals(instances): totals[start.date()] += instance.duration trace = go.Bar( - name='Total sleep', + name=_('Total sleep'), x=list(totals.keys()), y=[td.seconds/3600 for td in totals.values()], hoverinfo='text', @@ -46,10 +47,10 @@ def sleep_totals(instances): layout_args = utils.default_graph_layout_options() layout_args['barmode'] = 'stack' - layout_args['title'] = 'Sleep Totals' - layout_args['xaxis']['title'] = 'Date' + layout_args['title'] = _('Sleep Totals') + layout_args['xaxis']['title'] = _('Date') layout_args['xaxis']['rangeselector'] = utils.rangeselector_date() - layout_args['yaxis']['title'] = 'Hours of sleep' + layout_args['yaxis']['title'] = _('Hours of sleep') fig = go.Figure({ 'data': [trace], diff --git a/reports/graphs/weight_weight.py b/reports/graphs/weight_weight.py index dad70568..11eeea12 100644 --- a/reports/graphs/weight_weight.py +++ b/reports/graphs/weight_weight.py @@ -1,4 +1,6 @@ # -*- coding: utf-8 -*- +from django.utils.translation import gettext as _ + import plotly.offline as plotly import plotly.graph_objs as go @@ -14,7 +16,7 @@ def weight_weight(objects): objects = objects.order_by('-date') trace = go.Scatter( - name='Weight', + name=_('Weight'), x=list(objects.values_list('date', flat=True)), y=list(objects.values_list('weight', flat=True)), fill='tozeroy', @@ -22,10 +24,10 @@ def weight_weight(objects): layout_args = utils.default_graph_layout_options() layout_args['barmode'] = 'stack' - layout_args['title'] = 'Weight' - layout_args['xaxis']['title'] = 'Date' + layout_args['title'] = _('Weight') + layout_args['xaxis']['title'] = _('Date') layout_args['xaxis']['rangeselector'] = utils.rangeselector_date() - layout_args['yaxis']['title'] = 'Weight' + layout_args['yaxis']['title'] = _('Weight') fig = go.Figure({ 'data': [trace], diff --git a/reports/templates/reports/diaperchange_lifetimes.html b/reports/templates/reports/diaperchange_lifetimes.html index fb828e72..d6616254 100644 --- a/reports/templates/reports/diaperchange_lifetimes.html +++ b/reports/templates/reports/diaperchange_lifetimes.html @@ -1,8 +1,9 @@ {% extends 'reports/report_base.html' %} +{% load i18n %} -{% block title %}Diaper Lifetimes - {{ object }}{% endblock %} +{% block title %}{% trans "Diaper Lifetimes" %} - {{ object }}{% endblock %} {% block breadcrumbs %} {{ block.super }} - + {% endblock %} diff --git a/reports/templates/reports/diaperchange_types.html b/reports/templates/reports/diaperchange_types.html index be74ebb9..08407907 100644 --- a/reports/templates/reports/diaperchange_types.html +++ b/reports/templates/reports/diaperchange_types.html @@ -1,8 +1,9 @@ {% extends 'reports/report_base.html' %} +{% load i18n %} -{% block title %}Diaper Change Types - {{ object }}{% endblock %} +{% block title %}{% trans "Diaper Change Types" %} - {{ object }}{% endblock %} {% block breadcrumbs %} {{ block.super }} - + {% endblock %} diff --git a/reports/templates/reports/feeding_duration.html b/reports/templates/reports/feeding_duration.html index bd216360..964121ef 100644 --- a/reports/templates/reports/feeding_duration.html +++ b/reports/templates/reports/feeding_duration.html @@ -1,8 +1,9 @@ {% extends 'reports/report_base.html' %} +{% load i18n %} -{% block title %}Average Feeding Durations - {{ object }}{% endblock %} +{% block title %}{% trans "Average Feeding Durations" %} - {{ object }}{% endblock %} {% block breadcrumbs %} {{ block.super }} - + {% endblock %} diff --git a/reports/templates/reports/report_base.html b/reports/templates/reports/report_base.html index 92065b73..8f584516 100644 --- a/reports/templates/reports/report_base.html +++ b/reports/templates/reports/report_base.html @@ -1,12 +1,12 @@ {% extends 'babybuddy/page.html' %} -{% load static %} +{% load i18n static %} {% block title %}{% endblock %} {% block breadcrumbs %} - + - + {% endblock %} {% block content %} @@ -16,7 +16,7 @@ {% else %}
- There is no enough data to generate this report. + {% trans "There is no enough data to generate this report." %}
{% endif %} diff --git a/reports/templates/reports/sleep_pattern.html b/reports/templates/reports/sleep_pattern.html index 1b457a89..a650a3ce 100644 --- a/reports/templates/reports/sleep_pattern.html +++ b/reports/templates/reports/sleep_pattern.html @@ -1,8 +1,9 @@ {% extends 'reports/report_base.html' %} +{% load i18n %} -{% block title %}Sleep Patterns - {{ object }}{% endblock %} +{% block title %}{% trans "Sleep Pattern" %} - {{ object }}{% endblock %} {% block breadcrumbs %} {{ block.super }} - + {% endblock %} diff --git a/reports/templates/reports/sleep_totals.html b/reports/templates/reports/sleep_totals.html index e5475436..fe8f84cb 100644 --- a/reports/templates/reports/sleep_totals.html +++ b/reports/templates/reports/sleep_totals.html @@ -1,8 +1,9 @@ {% extends 'reports/report_base.html' %} +{% load i18n %} -{% block title %}Sleep Totals - {{ object }}{% endblock %} +{% block title %}{% trans "Sleep Totals" %} - {{ object }}{% endblock %} {% block breadcrumbs %} {{ block.super }} - + {% endblock %} diff --git a/reports/templates/reports/weight_change.html b/reports/templates/reports/weight_change.html index 72c75a3e..3e5a1f22 100644 --- a/reports/templates/reports/weight_change.html +++ b/reports/templates/reports/weight_change.html @@ -1,8 +1,9 @@ {% extends 'reports/report_base.html' %} +{% load i18n %} -{% block title %}Weight - {{ object }}{% endblock %} +{% block title %}{% trans "Weight" %} - {{ object }}{% endblock %} {% block breadcrumbs %} {{ block.super }} - + {% endblock %}