improve season title display
This commit is contained in:
parent
d48a18b3f4
commit
f543e7be63
19 changed files with 70 additions and 33 deletions
|
@ -592,7 +592,7 @@ class Item(PolymorphicModel):
|
|||
|
||||
def get_localized_title(self) -> str | None:
|
||||
if self.localized_title:
|
||||
locales = get_current_locales()
|
||||
locales = get_current_locales() + PREFERRED_LOCALES
|
||||
for loc in locales:
|
||||
v = next(
|
||||
filter(lambda t: t["lang"] == loc, self.localized_title), {}
|
||||
|
|
|
@ -198,20 +198,20 @@
|
|||
</div>
|
||||
<div id="item-title-more" class="middle">
|
||||
<hgroup>
|
||||
{% if item.display_subtitle %}<p>{{ item.display_subtitle }}</p>{% endif %}
|
||||
{% if item.orig_title %}
|
||||
<p>
|
||||
{{ item.orig_title }}
|
||||
<small>
|
||||
{% if item.season_number %}Season {{ item.season_number }}{% endif %}
|
||||
</small>
|
||||
</p>
|
||||
{% endif %}
|
||||
{% if item.parent_item %}
|
||||
<p>
|
||||
<p>
|
||||
{% if item.display_subtitle %}{{ item.display_subtitle }}{% endif %}
|
||||
{% if item.orig_title and item.orig_title != item.display_title %}
|
||||
<p>
|
||||
{{ item.orig_title }}
|
||||
<small>
|
||||
{% if item.season_number %}Season {{ item.season_number }}{% endif %}
|
||||
</small>
|
||||
</p>
|
||||
{% endif %}
|
||||
{% if item.parent_item %}
|
||||
{% trans 'part of' %} {{ item.parent_item.type.label }}: <span><a href="{{ item.parent_item.url }}"></span>{{ item.parent_item.display_title }}</a>
|
||||
</p>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
</p>
|
||||
{% if item.author or item.translator %}
|
||||
<p>
|
||||
<i>
|
||||
|
|
|
@ -48,6 +48,7 @@ from catalog.common import (
|
|||
jsondata,
|
||||
)
|
||||
from catalog.common.models import LANGUAGE_CHOICES_JSONFORM, LanguageListField
|
||||
from common.models.lang import RE_LOCALIZED_SEASON_NUMBERS, localize_number
|
||||
|
||||
|
||||
class TVShowInSchema(ItemInSchema):
|
||||
|
@ -248,6 +249,9 @@ class TVShow(Item):
|
|||
def child_items(self):
|
||||
return self.all_seasons
|
||||
|
||||
def get_season_count(self):
|
||||
return self.season_count or self.seasons.all().count()
|
||||
|
||||
|
||||
class TVSeason(Item):
|
||||
if TYPE_CHECKING:
|
||||
|
@ -398,26 +402,26 @@ class TVSeason(Item):
|
|||
]
|
||||
return [(i.value, i.label) for i in id_types]
|
||||
|
||||
@property
|
||||
@cached_property
|
||||
def display_title(self):
|
||||
if self.season_number and self.parent_item:
|
||||
if self.parent_item and (
|
||||
self.parent_item.season_count == 1 or not self.parent_item.season_count
|
||||
):
|
||||
"""
|
||||
returns season title for display:
|
||||
- "Season Title" if it's not a bare "Season X"
|
||||
- "Show Title" if it's the only season
|
||||
- "Show Title Season X" with some localization
|
||||
"""
|
||||
s = super().display_title
|
||||
if RE_LOCALIZED_SEASON_NUMBERS.sub("", s) == "" and self.parent_item:
|
||||
if self.parent_item.get_season_count() == 1:
|
||||
return self.parent_item.display_title
|
||||
else:
|
||||
return _("{show_title} S{season_number}").format(
|
||||
elif self.season_number:
|
||||
return _("{show_title} Season {season_number}").format(
|
||||
show_title=self.parent_item.display_title,
|
||||
season_number=self.season_number,
|
||||
season_number=localize_number(self.season_number),
|
||||
)
|
||||
else:
|
||||
return super().display_title
|
||||
|
||||
@property
|
||||
def display_subtitle(self):
|
||||
return (
|
||||
super().display_title if self.season_number and self.parent_item else None
|
||||
)
|
||||
else:
|
||||
return f"{self.parent_item.display_title} {s}"
|
||||
return s
|
||||
|
||||
def update_linked_items_from_external_resource(self, resource):
|
||||
for w in resource.required_resources:
|
||||
|
|
|
@ -240,6 +240,10 @@ ZH_LANGUAGE_SUBTAGS = {
|
|||
"wuu": _("Wu Chinese"),
|
||||
"hak": _("Hakka Chinese"),
|
||||
}
|
||||
RE_LOCALIZED_SEASON_NUMBERS = re.compile(
|
||||
r"〇|一|二|三|四|五|六|七|八|九|零|十|\d|\s|\.|S|Season|#|第|季",
|
||||
flags=re.IGNORECASE,
|
||||
)
|
||||
|
||||
|
||||
def get_preferred_locales():
|
||||
|
@ -257,6 +261,23 @@ def get_preferred_locales():
|
|||
PREFERRED_LOCALES = get_preferred_locales()
|
||||
|
||||
|
||||
def localize_number(i: int) -> str:
|
||||
lang = get_language().lower()
|
||||
if lang == "zh" or lang.startswith("zh-"):
|
||||
# TODO this works but can be much better
|
||||
if i < 0 or i > 99:
|
||||
return str(i)
|
||||
s = "零一二三四五六七八九"
|
||||
match i // 10:
|
||||
case 0:
|
||||
return s[i % 10]
|
||||
case 1:
|
||||
return "十" + s[i % 10]
|
||||
case _:
|
||||
return s[i // 10] + "十" + s[i % 10]
|
||||
return str(i)
|
||||
|
||||
|
||||
def get_base_lang_list():
|
||||
langs = {}
|
||||
for k in PREFERRED_LANGUAGES + TOP_USED_LANG:
|
||||
|
|
|
@ -76,6 +76,7 @@
|
|||
|
||||
#item-title-more {
|
||||
margin-top: 0;
|
||||
margin-bottom: 1em;
|
||||
}
|
||||
|
||||
#item-title h1 {
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
<script src="{{ cdn_url }}/npm/hyperscript.org@0.9.12"></script>
|
||||
<link rel="stylesheet"
|
||||
href="{{ cdn_url }}/npm/@picocss/pico@2/css/pico.min.css" />
|
||||
<link href="{% sass_src 'scss/neodb.scss' %}?xxddddddddxdd"
|
||||
<link href="{% sass_src 'scss/neodb.scss' %}"
|
||||
rel="stylesheet"
|
||||
type="text/css" />
|
||||
<link href="{{ cdn_url }}/npm/@fortawesome/fontawesome-free@6.5.2/css/all.min.css"
|
||||
|
|
|
@ -1370,7 +1370,7 @@ msgstr "单集长度"
|
|||
|
||||
#: catalog/tv/models.py:409
|
||||
#, python-brace-format
|
||||
msgid "{show_title} S{season_number}"
|
||||
msgid "{show_title} Season {season_number}"
|
||||
msgstr "{show_title} 第{season_number}季"
|
||||
|
||||
#: catalog/tv/models.py:461
|
||||
|
|
|
@ -1370,7 +1370,7 @@ msgstr "單集長度"
|
|||
|
||||
#: catalog/tv/models.py:409
|
||||
#, python-brace-format
|
||||
msgid "{show_title} S{season_number}"
|
||||
msgid "{show_title} Season {season_number}"
|
||||
msgstr "{show_title} 第{season_number}季"
|
||||
|
||||
#: catalog/tv/models.py:461
|
||||
|
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Loading…
Add table
Reference in a new issue