Move translations to filter

This commit is contained in:
Mouse Reeve 2022-02-28 11:05:12 -08:00
parent ab1c7c6d0a
commit 0f5fd6be15
2 changed files with 21 additions and 11 deletions

View file

@ -1,12 +1,4 @@
{% load i18n %} {% load i18n %}
{% if shelf.identifier == 'all' %} {% load shelf_tags %}
{% trans "All books" %}
{% elif shelf.identifier == 'to-read' %} {{ shelf|translate_shelf_name }}
{% trans "To Read" %}
{% elif shelf.identifier == 'reading' %}
{% trans "Currently Reading" %}
{% elif shelf.identifier == 'read' %}
{% trans "Read" %}
{% else %}
{{ shelf.name }}
{% endif %}

View file

@ -1,5 +1,6 @@
""" Filters and tags related to shelving books """ """ Filters and tags related to shelving books """
from django import template from django import template
from django.utils.translation import gettext_lazy as _
from bookwyrm import models from bookwyrm import models
from bookwyrm.utils import cache from bookwyrm.utils import cache
@ -32,6 +33,23 @@ def get_next_shelf(current_shelf):
return "to-read" 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) @register.simple_tag(takes_context=True)
def active_shelf(context, book): def active_shelf(context, book):
"""check what shelf a user has a book on, if any""" """check what shelf a user has a book on, if any"""