diff --git a/bookwyrm/templates/snippets/shelf_selector.html b/bookwyrm/templates/snippets/shelf_selector.html index 4b3ad4bd..2d1f2a83 100644 --- a/bookwyrm/templates/snippets/shelf_selector.html +++ b/bookwyrm/templates/snippets/shelf_selector.html @@ -71,7 +71,9 @@ {% csrf_token %} - + {% endif %} diff --git a/bookwyrm/templates/snippets/shelve_button/shelve_button_dropdown_options.html b/bookwyrm/templates/snippets/shelve_button/shelve_button_dropdown_options.html index 1fa26a88..2b87e21f 100644 --- a/bookwyrm/templates/snippets/shelve_button/shelve_button_dropdown_options.html +++ b/bookwyrm/templates/snippets/shelve_button/shelve_button_dropdown_options.html @@ -63,7 +63,7 @@ diff --git a/bookwyrm/templates/snippets/translated_shelf_name.html b/bookwyrm/templates/snippets/translated_shelf_name.html index 4da47e37..966135f5 100644 --- a/bookwyrm/templates/snippets/translated_shelf_name.html +++ b/bookwyrm/templates/snippets/translated_shelf_name.html @@ -1,12 +1,4 @@ {% load i18n %} -{% if shelf.identifier == 'all' %} - {% trans "All books" %} -{% elif shelf.identifier == 'to-read' %} - {% trans "To Read" %} -{% elif shelf.identifier == 'reading' %} - {% trans "Currently Reading" %} -{% elif shelf.identifier == 'read' %} - {% trans "Read" %} -{% else %} - {{ shelf.name }} -{% endif %} +{% load shelf_tags %} + +{{ shelf|translate_shelf_name }} diff --git a/bookwyrm/templatetags/shelf_tags.py b/bookwyrm/templatetags/shelf_tags.py index 6c4f59c3..4c15786a 100644 --- a/bookwyrm/templatetags/shelf_tags.py +++ b/bookwyrm/templatetags/shelf_tags.py @@ -1,5 +1,6 @@ """ Filters and tags related to shelving books """ from django import template +from django.utils.translation import gettext_lazy as _ from bookwyrm import models from bookwyrm.utils import cache @@ -32,6 +33,24 @@ def get_next_shelf(current_shelf): return "to-read" +@register.filter(name="translate_shelf_name") +def get_translated_shelf_name(shelf): + """produced translated shelf nidentifierame""" + if not shelf: + return "" + # support obj or dict + identifier = shelf["identifier"] if isinstance(shelf, dict) else shelf.identifier + if identifier == "all": + return _("All books") + if identifier == "to-read": + return _("To Read") + if identifier == "reading": + return _("Currently Reading") + if identifier == "read": + return _("Read") + return shelf["name"] if isinstance(shelf, dict) else shelf.name + + @register.simple_tag(takes_context=True) def active_shelf(context, book): """check what shelf a user has a book on, if any"""