// @vitest-environment jsdom // // The server's closed English vocabularies, named in the reader's language — through the REAL // catalog, so a missing or misnamed key shows here as the English word coming through. import { describe, expect, it } from "vitest"; import i18n from "../i18n"; import { languageName, profileName, regionName, trackLabel, vocab } from "./vocab"; const hu = i18n.getFixedT("hu"); const en = i18n.getFixedT("en"); describe("a vocabulary word", () => { it.each([ ["crewJob", "Director of Photography", "Operatőr"], ["crewJob", "Executive Producer", "Vezető producer"], ["department", "Acting", "Színészet"], ["autoTag", "Health & Fitness", "Egészség és fitnesz"], ["autoTag", "Hungarian", "Magyar"], ["profile", "Video only (MP4)", "Csak videó (MP4)"], ["topic", "Lifestyle_(sociology)", "Életmód"], // Plex's certificate words came through in English on the info badge and the filter. ["certificate", "Not Rated", "Nincs besorolva"], ["certificate", "Approved", "Jóváhagyva"], ["certificate", "Passed", "Engedélyezve"], ] as const)("%s %j reads %j in Hungarian", (group, word, shown) => { expect(vocab(hu, group, word)).toBe(shown); }); it("the English reader sees the word as it was", () => { expect(vocab(en, "crewJob", "Director of Photography")).toBe("Director of Photography"); expect(vocab(en, "topic", "Pop_music", "Pop music")).toBe("Pop music"); }); it("a certificate code reads the same in every language", () => { expect(vocab(hu, "certificate", "PG-13")).toBe("PG-13"); expect(vocab(hu, "certificate", "TV-MA")).toBe("TV-MA"); }); it("an unknown word is shown, not hidden or keyed", () => { expect(vocab(hu, "crewJob", "Gaffer")).toBe("Gaffer"); expect(vocab(hu, "topic", "Knitting_(craft)", "Knitting (craft)")).toBe("Knitting (craft)"); }); }); describe("a country", () => { it("is named from its code in the reader's language", () => { expect(regionName(hu, "US", "hu", "United States of America")).toBe("Egyesült Államok"); expect(regionName(en, "DE", "en", "Germany")).toBe("Germany"); }); it("that no longer exists keeps its own name — Intl would call Yugoslavia Serbia", () => { expect(regionName(hu, "YU", "hu", "Yugoslavia")).toBe("Jugoszlávia"); expect(regionName(hu, "SU", "hu", "Soviet Union")).toBe("Szovjetunió"); expect(regionName(en, "XI", "en", "Northern Ireland")).toBe("Northern Ireland"); }); it("without a code shows the stored name", () => { expect(regionName(hu, null, "hu", "Hungary")).toBe("Hungary"); }); }); describe("a language", () => { it("stands alone capitalized, region kept", () => { expect(languageName("hu", "hu")).toBe("Magyar"); expect(languageName("en-US", "en")).toBe("American English"); }); it("falls back to what was given for a tag Intl cannot name", () => { expect(languageName("qqq", "hu", "Klingon")).toBe("Klingon"); expect(languageName("und", "hu", "Unknown")).toBe("Unknown"); // "undetermined": no language }); }); describe("a player track", () => { const track = { ord: 0, label: "English (AC3 5.1)", lang_tag: "en-US", detail: "AC3 5.1" }; it("is named from its language, not Plex's server-language title", () => { expect(trackLabel(hu, track, "audio", "hu")).toBe("Angol (AC3 5.1)"); expect(trackLabel(en, track, "audio", "en")).toBe("English (AC3 5.1)"); }); it("says forced / SDH and translates the channel word", () => { expect( trackLabel( hu, { ord: 1, label: "magyar Forced", lang_tag: "hu", forced: true }, "subtitle", "hu", ), ).toBe("Magyar, kényszerített"); expect( trackLabel( hu, { ord: 2, label: "中文", lang_tag: "zh", detail: "EAC3 Stereo" }, "audio", "hu", ), ).toBe("Kínai (EAC3 sztereó)"); expect( trackLabel( en, { ord: 3, label: "English SDH", lang_tag: "en", hearing_impaired: true }, "subtitle", "en", ), ).toBe("English, SDH"); }); it("with no language keeps Plex's title, and with nothing is numbered", () => { expect(trackLabel(hu, { ord: 0, label: "Commentary" }, "audio", "hu")).toBe("Commentary"); expect(trackLabel(hu, { ord: 2, label: null, lang_tag: "und" }, "audio", "hu")).toBe( "3. hangsáv", ); expect(trackLabel(hu, { ord: 1, label: null }, "subtitle", "hu")).toBe("2. felirat"); expect(trackLabel(en, { ord: 0, label: null }, "audio", "en")).toBe("Audio 1"); }); }); describe("a download profile", () => { it("built in, is named in the reader's language; the user's own stays as typed", () => { expect(profileName(hu, { name: "Audio (MP3)", is_builtin: true })).toBe("Hang (MP3)"); expect(profileName(hu, { name: "Audio (MP3)", is_builtin: false })).toBe("Audio (MP3)"); }); });