diff --git a/bookwyrm/templates/snippets/translated_shelf_name.html b/bookwyrm/templates/snippets/translated_shelf_name.html index 4da47e370..966135f51 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 6c4f59c36..a2788826b 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,23 @@ 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 "" + identifier = 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 + + @register.simple_tag(takes_context=True) def active_shelf(context, book): """check what shelf a user has a book on, if any"""