Use gettext to add subtitle to short titles (use variable for length).
This commit is contained in:
@ -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
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user