From 8d6f49547be90610c56255140c06698b8a756f0c Mon Sep 17 00:00:00 2001 From: Deimos Date: Wed, 17 Jul 2019 17:01:08 -0600 Subject: [PATCH] Templates: use pluralize macro wherever possible Uses the new pluralize macro I added to simplify/shorten other cases where I was using {% trans %} previously. The only exception was for "vote"/"votes" in the topic voting button, since those are in separate HTML elements so it wouldn't work very cleanly through the macro. --- .../tildes/templates/macros/comments.jinja2 | 17 +++------------ tildes/tildes/templates/macros/groups.jinja2 | 10 +++------ tildes/tildes/templates/macros/topics.jinja2 | 7 ++----- tildes/tildes/templates/macros/user.jinja2 | 14 ++++--------- tildes/tildes/templates/macros/utils.jinja2 | 10 ++++----- tildes/tildes/templates/topic.jinja2 | 21 +++---------------- 6 files changed, 20 insertions(+), 59 deletions(-) diff --git a/tildes/tildes/templates/macros/comments.jinja2 b/tildes/tildes/templates/macros/comments.jinja2 index a69b7de..15a8729 100644 --- a/tildes/tildes/templates/macros/comments.jinja2 +++ b/tildes/tildes/templates/macros/comments.jinja2 @@ -5,6 +5,7 @@ {% from 'datetime.jinja2' import adaptive_date_responsive %} {% from 'forms.jinja2' import markdown_textarea %} {% from 'links.jinja2' import username_linked %} +{% from 'utils.jinja2' import pluralize %} {% macro render_single_comment(comment) %} {{ render_comment_tree([comment], is_individual_comment=True) }} @@ -92,13 +93,7 @@ {% if request.has_permission('view', comment) %} {# Show votes at the top only if it's your own comment #} {% if request.user == comment.user and comment.num_votes > 0 %} -
{{ comment.num_votes }} - {% trans num_votes=comment.num_votes %} - vote - {% pluralize %} - votes - {% endtrans %} -
+
{{ pluralize(comment.num_votes, "vote") }}
{% endif %} {% if comment.is_label_active("exemplary") and request.has_permission("view_exemplary_reasons", comment) %} @@ -144,13 +139,7 @@ {# Show votes at the bottom only if the viewer is logged out #} {% if not request.user and comment.num_votes > 0 %} -
{{ comment.num_votes }} - {% trans num_votes=comment.num_votes %} - vote - {% pluralize %} - votes - {% endtrans %} -
+
{{ pluralize(comment.num_votes, "vote") }}
{% endif %} diff --git a/tildes/tildes/templates/macros/groups.jinja2 b/tildes/tildes/templates/macros/groups.jinja2 index d92ca2b..56c89e6 100644 --- a/tildes/tildes/templates/macros/groups.jinja2 +++ b/tildes/tildes/templates/macros/groups.jinja2 @@ -1,15 +1,11 @@ {# Copyright (c) 2018 Tildes contributors #} {# SPDX-License-Identifier: AGPL-3.0-or-later #} +{% from 'utils.jinja2' import pluralize %} + {% macro render_group_subscription_box(group) %}
- - {% trans num_subscriptions=group.num_subscriptions %} - {{ num_subscriptions }} subscriber - {% pluralize %} - {{ num_subscriptions }} subscribers - {% endtrans %} - + {{ pluralize(group.num_subscriptions, "subscriber") }} {% if request.has_permission('subscribe', group) %} {% if group.user_subscribed %} diff --git a/tildes/tildes/templates/macros/topics.jinja2 b/tildes/tildes/templates/macros/topics.jinja2 index 4691c65..b2c72f8 100644 --- a/tildes/tildes/templates/macros/topics.jinja2 +++ b/tildes/tildes/templates/macros/topics.jinja2 @@ -3,6 +3,7 @@ {% from 'macros/datetime.jinja2' import adaptive_date_responsive %} {% from 'macros/links.jinja2' import group_linked, username_linked %} +{% from 'utils.jinja2' import pluralize %} {% macro render_topic_for_listing(topic, show_group=False, rank=None) %}
- {% trans num_comments=topic.num_comments %} - {{ num_comments }} comment - {% pluralize %} - {{ num_comments }} comments - {% endtrans %} + {{ pluralize(topic.num_comments, "comment") }} {% if topic.comments_since_last_visit is defined and topic.comments_since_last_visit %} diff --git a/tildes/tildes/templates/macros/user.jinja2 b/tildes/tildes/templates/macros/user.jinja2 index 4795deb..8876ae0 100644 --- a/tildes/tildes/templates/macros/user.jinja2 +++ b/tildes/tildes/templates/macros/user.jinja2 @@ -1,6 +1,8 @@ {# Copyright (c) 2018 Tildes contributors #} {# SPDX-License-Identifier: AGPL-3.0-or-later #} +{% from 'utils.jinja2' import pluralize %} + {% macro logged_in_user_info() %}