Translations: Allow to change field order for relative date form field (#4738)

This commit is contained in:
Raphael Michel
2025-01-14 13:48:37 +01:00
committed by GitHub
parent 6b5fd07535
commit ff6b4ae7bf
3 changed files with 15 additions and 14 deletions

View File

@@ -222,6 +222,12 @@ class RelativeDateTimeWidget(forms.MultiWidget):
def get_context(self, name, value, attrs):
ctx = super().get_context(name, value, attrs)
ctx['required'] = self.status_choices[0][0] == 'unset'
ctx['rendered_subwidgets'] = [
self._render(w['template_name'], {**ctx, 'widget': w})
for w in ctx['widget']['subwidgets']
]
return ctx

View File

@@ -11,10 +11,9 @@
{% if selopt.value == "absolute" %}
{% include widget.subwidgets.1.template_name with widget=widget.subwidgets.1 %}
{% elif selopt.value == "relative" %}
{% include widget.subwidgets.2.template_name with widget=widget.subwidgets.2 %}
{% trans "days" %}
{% include widget.subwidgets.4.template_name with widget=widget.subwidgets.4 %}
{% include widget.subwidgets.3.template_name with widget=widget.subwidgets.3 %}
{% blocktrans trimmed with number=rendered_subwidgets.2 relation=rendered_subwidgets.4 relation_to=rendered_subwidgets.3 %}
{{ number }} days {{ relation }} {{ relation_to }}
{% endblocktrans %}
{% endif %}
</div>
{% endfor %}

View File

@@ -11,17 +11,13 @@
{% if selopt.value == "absolute" %}
{% include widget.subwidgets.1.template_name with widget=widget.subwidgets.1 %}
{% elif selopt.value == "relative_minutes" %}
{% include widget.subwidgets.5.template_name with widget=widget.subwidgets.5 %}
{% trans "minutes" %}
{% include widget.subwidgets.7.template_name with widget=widget.subwidgets.7 %}
{% include widget.subwidgets.3.template_name with widget=widget.subwidgets.3 %}
{% blocktrans trimmed with number=rendered_subwidgets.5 relation=rendered_subwidgets.7 relation_to=rendered_subwidgets.3 %}
{{ number }} minutes {{ relation }} {{ relation_to }}
{% endblocktrans %}
{% elif selopt.value == "relative" %}
{% include widget.subwidgets.2.template_name with widget=widget.subwidgets.2 %}
{% trans "days" %}
{% include widget.subwidgets.8.template_name with widget=widget.subwidgets.8 %}
{% include widget.subwidgets.6.template_name with widget=widget.subwidgets.6 %}
{% trans "at" %}
{% include widget.subwidgets.4.template_name with widget=widget.subwidgets.4 %}
{% blocktrans trimmed with number=rendered_subwidgets.2 relation=rendered_subwidgets.8 relation_to=rendered_subwidgets.6 time_of_day=rendered_subwidgets.4 %}
{{ number }} days {{ relation }} {{ relation_to }} at {{ time_of_day }}
{% endblocktrans %}
{% endif %}
</div>
{% endfor %}