Use gettext to add subtitle to short titles (use variable for length).

This commit is contained in:
Fabien Basmaison
2021-06-09 18:51:20 +02:00
parent b8922bae19
commit 0ecea5710b
3 changed files with 45 additions and 36 deletions

View File

@ -2,6 +2,7 @@
import os
from uuid import uuid4
from django import template
from django.utils.translation import gettext_lazy as _
register = template.Library()
@ -20,13 +21,16 @@ def get_user_identifier(user):
@register.filter(name="book_title")
def get_title(book):
def get_title(book, too_short=6):
"""display the subtitle if the title is short"""
if not book:
return ""
title = book.title
if len(title) < 6 and book.subtitle:
title = "{:s} ({:s})".format(title, book.subtitle)
if len(title) < too_short and book.subtitle:
title = _("%(title)s: %(subtitle)s") % {
"title": title,
"subtitle": book.subtitle
}
return title