Self hosted FLOSS fitness/workout, nutrition and weight tracker
Add helper tag to translate weight units
Roland Geider95d39995b2a1
diff --git a/wger/core/templates/index.html b/wger/core/templates/index.htmlindex 8ef35df57..a45b0c9ac 100644--- a/wger/core/templates/index.html+++ b/wger/core/templates/index.html@@ -1,6 +1,7 @@{% extends "base.html" %}{% load i18n %}{% load staticfiles %}+{% load wger_extras %}{% block title %}{% trans "Dashboard" %}{% endblock %}@@ -111,14 +112,13 @@ day in your current workout:{% endblocktrans %} <strong>{{current_workout}}</str{% trans "Energy" %}: {{nutritional_info.total.energy|floatformat}} {% trans "kcal" %}</li><li>- {% trans "Protein" %}: {{nutritional_info.total.protein|floatformat}}- {% trans "g" context "weight unit, i.e. grams" %}+ {% trans "Protein" %}: {{nutritional_info.total.protein|floatformat}} {% trans_weight_unit 'g' user %}</li><li>- {% trans "Carbohydrates" %}: {{nutritional_info.total.carbohydrates|floatformat}} {% trans "g" context "weight unit, i.e. grams" %}+ {% trans "Carbohydrates" %}: {{nutritional_info.total.carbohydrates|floatformat}} {% trans_weight_unit 'g' user %}</li><li>- {% trans "Fat" %}: {{nutritional_info.total.fat|floatformat}} {% trans "g" context "weight unit, i.e. grams" %}+ {% trans "Fat" %}: {{nutritional_info.total.fat|floatformat}} {% trans_weight_unit 'g' user %}</li></ul>@@ -133,12 +133,7 @@ day in your current workout:{% endblocktrans %} <strong>{{current_workout}}</str<p>{% trans "Your current weight is: "%}<strong>- {{weight.weight|floatformat}}- {% if user.userprofile.weight_unit == 'kg' %}- {% trans "kg" %}- {% else %}- {% trans "lb" %}- {% endif %}+ {{weight.weight|floatformat}} {% trans_weight_unit 'kg' user %}</strong></p>{% endif %}diff --git a/wger/core/templates/mobile/index.html b/wger/core/templates/mobile/index.htmlindex 091dd641c..a29061bba 100644--- a/wger/core/templates/mobile/index.html+++ b/wger/core/templates/mobile/index.html@@ -59,13 +59,13 @@{% trans "Energy" %}: {{nutritional_info.total.energy|floatformat}} {% trans "kcal" %}</li><li class="list-group-item">- {% trans "Protein" %}: {{nutritional_info.total.protein|floatformat}} {% trans "g" context "weight unit, i.e. grams" %}+ {% trans "Protein" %}: {{nutritional_info.total.protein|floatformat}} {% trans_weight_unit 'g' user %}</li><li class="list-group-item">- {% trans "Carbohydrates" %}: {{nutritional_info.total.carbohydrates|floatformat}} {% trans "g" context "weight unit, i.e. grams" %}+ {% trans "Carbohydrates" %}: {{nutritional_info.total.carbohydrates|floatformat}} {% trans_weight_unit 'g' user %}</li><li class="list-group-item">- {% trans "Fat" %}: {{nutritional_info.total.fat|floatformat}} {% trans "g" context "weight unit, i.e. grams" %}+ {% trans "Fat" %}: {{nutritional_info.total.fat|floatformat}} {% trans_weight_unit 'g' user %}</li></ul>@@ -73,12 +73,7 @@<p>{% trans "Your current weight is: "%}<strong>- {{weight.weight|floatformat}}- {% if user.userprofile.weight_unit == 'kg' %}- {% trans "kg" %}- {% else %}- {% trans "lb" %}- {% endif %}+ {{weight.weight|floatformat}} {% trans_weight_unit 'kg' user %}</strong></p>{% endif %}diff --git a/wger/manager/templates/day/log.html b/wger/manager/templates/day/log.htmlindex 04e10d2ec..c252fd3a7 100644--- a/wger/manager/templates/day/log.html+++ b/wger/manager/templates/day/log.html@@ -52,11 +52,7 @@ $(document).ready(function () {{% for form in value.forms %}<td>{% trans "Reps" %}</td><td>- {% if user.userprofile.weight_unit == 'kg' %}- {% trans "kg" %}- {% else %}- {% trans "lb" %}- {% endif %}+ {% trans_weight_unit 'kg' user %}</td>{% endfor %}</tr>diff --git a/wger/manager/templates/tags/render_weight_log.html b/wger/manager/templates/tags/render_weight_log.htmlindex d76c4b6f9..07fa5b6c0 100644--- a/wger/manager/templates/tags/render_weight_log.html+++ b/wger/manager/templates/tags/render_weight_log.html@@ -1,5 +1,6 @@{% load i18n %}{% load staticfiles %}+{% load wger_extras %}<div class="weight-chart-table-toggle" data-toggle-target="table-{{div_uuid}}"><p><a href="#">@@ -24,11 +25,7 @@<td style="text-align:right;">{% trans "Reps" %}</td><td></td><td style="padding:0px;">- {% if user.userprofile.weight_unit == 'kg' %}- {% trans "kg" %}- {% else %}- {% trans "lb" %}- {% endif %}+ {% trans_weight_unit 'kg' user %}</td></tr>{% for entry in entry_list %}diff --git a/wger/manager/templates/workout/timer.html b/wger/manager/templates/workout/timer.htmlindex 9e2cad416..529554fa9 100644--- a/wger/manager/templates/workout/timer.html+++ b/wger/manager/templates/workout/timer.html@@ -320,13 +320,7 @@ $(document).ready(function() {<div class="sub_header"><h2>{% if step.weight %}- {{step.reps}} × {{step.weight}}- {% if user.userprofile.weight_unit == 'kg' %}- {% trans "kg" %}- {% else %}- {% trans "lb" %}- {% endif %}- .+ {{step.reps}} × {{step.weight}} {% trans_weight_unit 'kg' user %}{% else %}{% if step.reps == 99 %}∞{% else %}{{step.reps}}{% endif %} {% trans "reps" %}{% endif %}diff --git a/wger/manager/templatetags/wger_extras.py b/wger/manager/templatetags/wger_extras.pyindex 8aef95c4c..97d0e4ef7 100644--- a/wger/manager/templatetags/wger_extras.py+++ b/wger/manager/templatetags/wger_extras.py@@ -16,6 +16,8 @@from django import templatefrom django.forms.widgets import CheckboxInput, ClearableFileInput+from django.utils.translation import ugettext_lazy as _+from django.utils.translation import pgettextfrom wger.utils.constants import PAGINATION_MAX_TOTAL_PAGESfrom wger.utils.constants import PAGINATION_PAGES_AROUND_CURRENT@@ -129,6 +131,27 @@ def auto_link_css(flavour='full', css=''):return 'class="{0}"'.format(css)+def trans_weight_unit(unit, user):+ '''+ Returns the correct (translated) weight unit++ :param unit: the weight unit. Allowed values are 'kg' and 'g'+ :param user: the user object, needed to access the profile+ :return: translated unit+ '''+ if user.userprofile.weight_unit == 'kg':+ if unit == 'kg':+ return _('kg')+ if unit == 'g':+ return pgettext("weight unit, i.e. grams", "g")+ else:+ if unit == 'kg':+ return _('lb')+ if unit == 'g':+ return pgettext("weight unit, i.e. ounces", "oz")++@register.filterdef format_username(user):'''