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:
|
def get_localized_title(self) -> str | None:
|
||||||
if self.localized_title:
|
if self.localized_title:
|
||||||
locales = get_current_locales()
|
locales = get_current_locales() + PREFERRED_LOCALES
|
||||||
for loc in locales:
|
for loc in locales:
|
||||||
v = next(
|
v = next(
|
||||||
filter(lambda t: t["lang"] == loc, self.localized_title), {}
|
filter(lambda t: t["lang"] == loc, self.localized_title), {}
|
||||||
|
|
|
@ -198,20 +198,20 @@
|
||||||
</div>
|
</div>
|
||||||
<div id="item-title-more" class="middle">
|
<div id="item-title-more" class="middle">
|
||||||
<hgroup>
|
<hgroup>
|
||||||
{% if item.display_subtitle %}<p>{{ item.display_subtitle }}</p>{% endif %}
|
<p>
|
||||||
{% if item.orig_title %}
|
{% if item.display_subtitle %}{{ item.display_subtitle }}{% endif %}
|
||||||
<p>
|
{% if item.orig_title and item.orig_title != item.display_title %}
|
||||||
{{ item.orig_title }}
|
<p>
|
||||||
<small>
|
{{ item.orig_title }}
|
||||||
{% if item.season_number %}Season {{ item.season_number }}{% endif %}
|
<small>
|
||||||
</small>
|
{% if item.season_number %}Season {{ item.season_number }}{% endif %}
|
||||||
</p>
|
</small>
|
||||||
{% endif %}
|
</p>
|
||||||
{% if item.parent_item %}
|
{% endif %}
|
||||||
<p>
|
{% 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>
|
{% 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 %}
|
{% if item.author or item.translator %}
|
||||||
<p>
|
<p>
|
||||||
<i>
|
<i>
|
||||||
|
|
|
@ -48,6 +48,7 @@ from catalog.common import (
|
||||||
jsondata,
|
jsondata,
|
||||||
)
|
)
|
||||||
from catalog.common.models import LANGUAGE_CHOICES_JSONFORM, LanguageListField
|
from catalog.common.models import LANGUAGE_CHOICES_JSONFORM, LanguageListField
|
||||||
|
from common.models.lang import RE_LOCALIZED_SEASON_NUMBERS, localize_number
|
||||||
|
|
||||||
|
|
||||||
class TVShowInSchema(ItemInSchema):
|
class TVShowInSchema(ItemInSchema):
|
||||||
|
@ -248,6 +249,9 @@ class TVShow(Item):
|
||||||
def child_items(self):
|
def child_items(self):
|
||||||
return self.all_seasons
|
return self.all_seasons
|
||||||
|
|
||||||
|
def get_season_count(self):
|
||||||
|
return self.season_count or self.seasons.all().count()
|
||||||
|
|
||||||
|
|
||||||
class TVSeason(Item):
|
class TVSeason(Item):
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
|
@ -398,26 +402,26 @@ class TVSeason(Item):
|
||||||
]
|
]
|
||||||
return [(i.value, i.label) for i in id_types]
|
return [(i.value, i.label) for i in id_types]
|
||||||
|
|
||||||
@property
|
@cached_property
|
||||||
def display_title(self):
|
def display_title(self):
|
||||||
if self.season_number and self.parent_item:
|
"""
|
||||||
if self.parent_item and (
|
returns season title for display:
|
||||||
self.parent_item.season_count == 1 or not self.parent_item.season_count
|
- "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
|
return self.parent_item.display_title
|
||||||
else:
|
elif self.season_number:
|
||||||
return _("{show_title} S{season_number}").format(
|
return _("{show_title} Season {season_number}").format(
|
||||||
show_title=self.parent_item.display_title,
|
show_title=self.parent_item.display_title,
|
||||||
season_number=self.season_number,
|
season_number=localize_number(self.season_number),
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
return super().display_title
|
return f"{self.parent_item.display_title} {s}"
|
||||||
|
return s
|
||||||
@property
|
|
||||||
def display_subtitle(self):
|
|
||||||
return (
|
|
||||||
super().display_title if self.season_number and self.parent_item else None
|
|
||||||
)
|
|
||||||
|
|
||||||
def update_linked_items_from_external_resource(self, resource):
|
def update_linked_items_from_external_resource(self, resource):
|
||||||
for w in resource.required_resources:
|
for w in resource.required_resources:
|
||||||
|
|
|
@ -240,6 +240,10 @@ ZH_LANGUAGE_SUBTAGS = {
|
||||||
"wuu": _("Wu Chinese"),
|
"wuu": _("Wu Chinese"),
|
||||||
"hak": _("Hakka Chinese"),
|
"hak": _("Hakka Chinese"),
|
||||||
}
|
}
|
||||||
|
RE_LOCALIZED_SEASON_NUMBERS = re.compile(
|
||||||
|
r"〇|一|二|三|四|五|六|七|八|九|零|十|\d|\s|\.|S|Season|#|第|季",
|
||||||
|
flags=re.IGNORECASE,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def get_preferred_locales():
|
def get_preferred_locales():
|
||||||
|
@ -257,6 +261,23 @@ def get_preferred_locales():
|
||||||
PREFERRED_LOCALES = 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():
|
def get_base_lang_list():
|
||||||
langs = {}
|
langs = {}
|
||||||
for k in PREFERRED_LANGUAGES + TOP_USED_LANG:
|
for k in PREFERRED_LANGUAGES + TOP_USED_LANG:
|
||||||
|
|
|
@ -76,6 +76,7 @@
|
||||||
|
|
||||||
#item-title-more {
|
#item-title-more {
|
||||||
margin-top: 0;
|
margin-top: 0;
|
||||||
|
margin-bottom: 1em;
|
||||||
}
|
}
|
||||||
|
|
||||||
#item-title h1 {
|
#item-title h1 {
|
||||||
|
|
|
@ -21,7 +21,7 @@
|
||||||
<script src="{{ cdn_url }}/npm/hyperscript.org@0.9.12"></script>
|
<script src="{{ cdn_url }}/npm/hyperscript.org@0.9.12"></script>
|
||||||
<link rel="stylesheet"
|
<link rel="stylesheet"
|
||||||
href="{{ cdn_url }}/npm/@picocss/pico@2/css/pico.min.css" />
|
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"
|
rel="stylesheet"
|
||||||
type="text/css" />
|
type="text/css" />
|
||||||
<link href="{{ cdn_url }}/npm/@fortawesome/fontawesome-free@6.5.2/css/all.min.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
|
#: catalog/tv/models.py:409
|
||||||
#, python-brace-format
|
#, python-brace-format
|
||||||
msgid "{show_title} S{season_number}"
|
msgid "{show_title} Season {season_number}"
|
||||||
msgstr "{show_title} 第{season_number}季"
|
msgstr "{show_title} 第{season_number}季"
|
||||||
|
|
||||||
#: catalog/tv/models.py:461
|
#: catalog/tv/models.py:461
|
||||||
|
|
|
@ -1370,7 +1370,7 @@ msgstr "單集長度"
|
||||||
|
|
||||||
#: catalog/tv/models.py:409
|
#: catalog/tv/models.py:409
|
||||||
#, python-brace-format
|
#, python-brace-format
|
||||||
msgid "{show_title} S{season_number}"
|
msgid "{show_title} Season {season_number}"
|
||||||
msgstr "{show_title} 第{season_number}季"
|
msgstr "{show_title} 第{season_number}季"
|
||||||
|
|
||||||
#: catalog/tv/models.py:461
|
#: 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