feat(i18n): the person page's biography in Hungarian, from TMDB's translation (E30 S4)

The /person fetch appends translations and keeps TMDB's Hungarian biography beside the instance-language
one (new plex_people.biography_hu, migration 0092). A Hungarian reader is served it, the English one when
TMDB has none. Already-enriched people are un-stamped, so their next open refetches them once.
This commit is contained in:
2026-09-29 23:44:48 +02:00
parent a39504e617
commit 519fbe2a18
5 changed files with 125 additions and 3 deletions
+71
View File
@@ -332,3 +332,74 @@ def test_person_detail_serves_bio_and_resolves_known_for(db, monkeypatch, overri
assert j["also_known_as"] == ["Alt Name"]
# Only the in-library known_for credit resolves to a card; the out-of-library one is dropped.
assert [c["title"] for c in j["known_for"]] == ["Known Movie"]
# --- E30 S4: the biography in the reader's language --------------------------------------------------
# The same /person request appends `translations`; the Hungarian one is kept beside the instance-language
# biography, and a Hungarian reader is served it, falling back to the English one when TMDB has none.
def _translation(lang: str, bio: str) -> dict:
return {"iso_639_1": lang, "iso_3166_1": lang.upper(), "data": {"biography": bio}}
def test_parse_person_keeps_the_hungarian_biography():
payload = {
**PAYLOAD,
"translations": {
"translations": [
_translation("de", "Ein Schauspieler."),
_translation("hu", " Ünnepelt színész. "),
]
},
}
assert plex_tmdb.parse_person(payload)["biography_hu"] == "Ünnepelt színész."
def test_parse_person_without_a_hungarian_biography():
assert plex_tmdb.parse_person(PAYLOAD)["biography_hu"] is None
blank = {**PAYLOAD, "translations": {"translations": [_translation("hu", " ")]}}
assert plex_tmdb.parse_person(blank)["biography_hu"] is None
def test_fetch_person_asks_for_the_translations():
client = plex_tmdb.TmdbClient.__new__(plex_tmdb.TmdbClient)
seen: list[dict] = []
client._get = lambda path, params=None: seen.append(params or {}) or {} # type: ignore[method-assign]
client.fetch_person(500)
assert "translations" in seen[0]["append_to_response"].split(",")
def test_person_detail_serves_the_biography_in_the_readers_language(db, monkeypatch, override_dep):
from datetime import datetime, timezone
done = datetime(2024, 1, 1, tzinfo=timezone.utc)
db.add(PlexLibrary(plex_key="7", title="Movies", kind="movie", enabled=True))
db.add_all(
[
PlexPerson(
name="Both P",
tmdb_person_id=1,
tmdb_enriched_at=done,
biography="English bio.",
biography_hu="Magyar életrajz.",
),
PlexPerson(
name="Only EN P", tmdb_person_id=2, tmdb_enriched_at=done, biography="Only English."
),
]
)
user = User(email="biolang@example.com")
db.add(user)
db.commit()
def bio(name: str, lang: str) -> str | None:
resp = _get(db, user, monkeypatch, override_dep, f"/api/plex/person/{name}?lang={lang}")
assert resp.status_code == 200, resp.text
return resp.json()["biography"]
assert bio("Both P", "hu") == "Magyar életrajz."
assert bio("Both P", "en") == "English bio."
assert (
bio("Only EN P", "hu") == "Only English."
) # TMDB has no Hungarian one: the English stands in