Browse Source

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.
merge-requests/74/head
Deimos 5 years ago
parent
commit
8d6f49547b
  1. 17
      tildes/tildes/templates/macros/comments.jinja2
  2. 10
      tildes/tildes/templates/macros/groups.jinja2
  3. 7
      tildes/tildes/templates/macros/topics.jinja2
  4. 14
      tildes/tildes/templates/macros/user.jinja2
  5. 10
      tildes/tildes/templates/macros/utils.jinja2
  6. 21
      tildes/tildes/templates/topic.jinja2

17
tildes/tildes/templates/macros/comments.jinja2

@ -5,6 +5,7 @@
{% from 'datetime.jinja2' import adaptive_date_responsive %} {% from 'datetime.jinja2' import adaptive_date_responsive %}
{% from 'forms.jinja2' import markdown_textarea %} {% from 'forms.jinja2' import markdown_textarea %}
{% from 'links.jinja2' import username_linked %} {% from 'links.jinja2' import username_linked %}
{% from 'utils.jinja2' import pluralize %}
{% macro render_single_comment(comment) %} {% macro render_single_comment(comment) %}
{{ render_comment_tree([comment], is_individual_comment=True) }} {{ render_comment_tree([comment], is_individual_comment=True) }}
@ -92,13 +93,7 @@
{% if request.has_permission('view', comment) %} {% if request.has_permission('view', comment) %}
{# Show votes at the top only if it's your own comment #} {# Show votes at the top only if it's your own comment #}
{% if request.user == comment.user and comment.num_votes > 0 %} {% if request.user == comment.user and comment.num_votes > 0 %}
<div class="comment-votes">{{ comment.num_votes }}
{% trans num_votes=comment.num_votes %}
vote
{% pluralize %}
votes
{% endtrans %}
</div>
<div class="comment-votes">{{ pluralize(comment.num_votes, "vote") }}</div>
{% endif %} {% endif %}
{% if comment.is_label_active("exemplary") and request.has_permission("view_exemplary_reasons", comment) %} {% 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 #} {# Show votes at the bottom only if the viewer is logged out #}
{% if not request.user and comment.num_votes > 0 %} {% if not request.user and comment.num_votes > 0 %}
<div class="comment-votes">{{ comment.num_votes }}
{% trans num_votes=comment.num_votes %}
vote
{% pluralize %}
votes
{% endtrans %}
</div>
<div class="comment-votes">{{ pluralize(comment.num_votes, "vote") }}</div>
{% endif %} {% endif %}
<menu class="btn-post"> <menu class="btn-post">

10
tildes/tildes/templates/macros/groups.jinja2

@ -1,15 +1,11 @@
{# Copyright (c) 2018 Tildes contributors <code@tildes.net> #} {# Copyright (c) 2018 Tildes contributors <code@tildes.net> #}
{# SPDX-License-Identifier: AGPL-3.0-or-later #} {# SPDX-License-Identifier: AGPL-3.0-or-later #}
{% from 'utils.jinja2' import pluralize %}
{% macro render_group_subscription_box(group) %} {% macro render_group_subscription_box(group) %}
<div class="group-subscription"> <div class="group-subscription">
<span class="group-subscription-count">
{% trans num_subscriptions=group.num_subscriptions %}
{{ num_subscriptions }} subscriber
{% pluralize %}
{{ num_subscriptions }} subscribers
{% endtrans %}
</span>
<span class="group-subscription-count">{{ pluralize(group.num_subscriptions, "subscriber") }}</span>
{% if request.has_permission('subscribe', group) %} {% if request.has_permission('subscribe', group) %}
{% if group.user_subscribed %} {% if group.user_subscribed %}

7
tildes/tildes/templates/macros/topics.jinja2

@ -3,6 +3,7 @@
{% from 'macros/datetime.jinja2' import adaptive_date_responsive %} {% from 'macros/datetime.jinja2' import adaptive_date_responsive %}
{% from 'macros/links.jinja2' import group_linked, username_linked %} {% 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) %} {% macro render_topic_for_listing(topic, show_group=False, rank=None) %}
<article id="topic-{{ topic.topic_id36 }}" <article id="topic-{{ topic.topic_id36 }}"
@ -65,11 +66,7 @@
href="{{ topic.permalink }}" href="{{ topic.permalink }}"
{% if request.user.open_new_tab_internal %}target="_blank"{% endif %} {% if request.user.open_new_tab_internal %}target="_blank"{% endif %}
> >
{% 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 %} {% if topic.comments_since_last_visit is defined and topic.comments_since_last_visit %}
<span class="topic-info-comments-new" title="Last visit {{ topic.last_visit_time|ago }}"> <span class="topic-info-comments-new" title="Last visit {{ topic.last_visit_time|ago }}">

14
tildes/tildes/templates/macros/user.jinja2

@ -1,6 +1,8 @@
{# Copyright (c) 2018 Tildes contributors <code@tildes.net> #} {# Copyright (c) 2018 Tildes contributors <code@tildes.net> #}
{# SPDX-License-Identifier: AGPL-3.0-or-later #} {# SPDX-License-Identifier: AGPL-3.0-or-later #}
{% from 'utils.jinja2' import pluralize %}
{% macro logged_in_user_info() %} {% macro logged_in_user_info() %}
<div class="logged-in-user-info"> <div class="logged-in-user-info">
{% if request.user %} {% if request.user %}
@ -8,21 +10,13 @@
{% if request.user.num_unread_messages > 0 %} {% if request.user.num_unread_messages > 0 %}
<a class="logged-in-user-alert" href="/messages/unread"> <a class="logged-in-user-alert" href="/messages/unread">
{% trans num_messages=request.user.num_unread_messages %}
{{ num_messages }} new message
{% pluralize %}
{{ num_messages }} new messages
{% endtrans %}
{{ pluralize(request.user.num_unread_messages, "new message") }}
</a> </a>
{% endif %} {% endif %}
{% if request.user.num_unread_notifications > 0 %} {% if request.user.num_unread_notifications > 0 %}
<a class="logged-in-user-alert" href="/notifications/unread"> <a class="logged-in-user-alert" href="/notifications/unread">
{% trans num_notifications=request.user.num_unread_notifications %}
{{ num_notifications }} new comment
{% pluralize %}
{{ num_notifications }} new comments
{% endtrans %}
{{ pluralize(request.user.num_unread_notifications, "new comment") }}
</a> </a>
{% endif %} {% endif %}
{# Only show the "Log in" link if we're not already on the login page #} {# Only show the "Log in" link if we're not already on the login page #}

10
tildes/tildes/templates/macros/utils.jinja2

@ -1,15 +1,15 @@
{# Copyright (c) 2019 Tildes contributors <code@tildes.net> #} {# Copyright (c) 2019 Tildes contributors <code@tildes.net> #}
{# SPDX-License-Identifier: AGPL-3.0-or-later #} {# SPDX-License-Identifier: AGPL-3.0-or-later #}
{% macro pluralize(counter, base_word, plural_word=None) %}
{% if not plural_word %}
{% set plural_word = base_word~"s" %}
{% macro pluralize(counter, singular_form, plural_form=None) %}
{% if not plural_form %}
{% set plural_form = singular_form~"s" %}
{% endif %} {% endif %}
{%- trans counter=counter -%} {%- trans counter=counter -%}
{{ counter }} {{ base_word }}
{{ counter }} {{ singular_form }}
{%- pluralize -%} {%- pluralize -%}
{{ counter }} {{ plural_word }}
{{ counter }} {{ plural_form }}
{%- endtrans %} {%- endtrans %}
{% endmacro %} {% endmacro %}

21
tildes/tildes/templates/topic.jinja2

@ -167,13 +167,7 @@
<section class="topic-comments"> <section class="topic-comments">
{% if comments %} {% if comments %}
<header class="topic-comments-header"> <header class="topic-comments-header">
<h2>
{% trans num_comments=topic.num_comments %}
{{ num_comments }} comment
{% pluralize %}
{{ num_comments }} comments
{% endtrans %}
</h2>
<h2>{{ pluralize(topic.num_comments, "comment") }}</h2>
<div class="btn-group"> <div class="btn-group">
<button class="btn btn-sm btn-light" data-js-comment-collapse-all-button>Collapse replies</button> <button class="btn btn-sm btn-light" data-js-comment-collapse-all-button>Collapse replies</button>
@ -256,17 +250,8 @@
<dt>Comments</dt> <dt>Comments</dt>
{% if topic.num_comments > 0 %} {% if topic.num_comments > 0 %}
<dd> <dd>
{% trans num_comments=topic.num_comments %}
{{ num_comments }} comment
{% pluralize %}
{{ num_comments }} comments
{% endtrans %}
{% trans num_top_level=comments.num_top_level %}
({{ num_top_level }} thread)
{% pluralize %}
({{ num_top_level }} threads)
{% endtrans %}
{{ pluralize(topic.num_comments, "comment") }}
({{ pluralize(comments.num_top_level, "thread") }})
</dd> </dd>
<dt>Last comment posted</dt> <dt>Last comment posted</dt>

Loading…
Cancel
Save