feat(plex): S6 frontend — language threading, rating badge, i18n parity
E5 S6 frontend half. Language threading (?lang=hu serves the HU overlay; en is the default): - api/plex.ts: `lang` on plexLibrary / plexFacets / plexItem / plexShow (only sent for hu, so EN URLs stay byte-stable); PlexItemDetail gains `rating`. - queryKeys: plexItem / plexShow take an optional trailing lang so a switch caches HU/EN separately; the ...rest keys (library/facets) already carry it. Prefix invalidations (qk.plexShow(id) / qk.plexItem(id)) still match either. - i18n: plexLang() collapses the UI language to en|hu for non-component code. - PlexBrowse / PlexSidebar: thread lang into the grid, facets, item and show queries (useTranslation re-renders on switch → the key changes → refetch). - plexPlayerHooks: the optimistic resume setQueryData now keys by plexLang() so it still lands on the language-keyed detail query. - Clear the genre-filter selection on a language switch — genre chips are language-specific strings, so a stale one silently empties the grid. IMDb-only rating badge (folded-in S5b review #5): - PlexInfo.tsx shows the IMDb badge + imdb.com link only when imdb_rating is present; otherwise it renders the Plex audience `rating` (no IMDb link/branding), so a non-IMDb score is never mislabelled. ratingMin filter keys off whichever score is shown. Tests: i18n parity.test.ts (en/hu key sets identical per namespace — currently green, no drift). FE gate green: tsc / knip / lint clean, 213 vitest tests pass.
This commit is contained in:
@@ -56,4 +56,11 @@ export function setLanguage(code: LangCode): void {
|
||||
document.documentElement.lang = code;
|
||||
}
|
||||
|
||||
// The Plex overlay serves only EN or HU metadata (E5 S6). Collapse the active UI language to one of
|
||||
// those for the `?lang=` param / query keys. Components read `i18n.language` off useTranslation (which
|
||||
// re-renders on switch); this singleton reader is for non-component code (e.g. plexPlayerHooks).
|
||||
export function plexLang(): "en" | "hu" {
|
||||
return i18n.language?.startsWith("hu") ? "hu" : "en";
|
||||
}
|
||||
|
||||
export default i18n;
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
// E5 S6: every locale namespace must carry the SAME key set in English and Hungarian. A key present
|
||||
// in one language but not the other renders the raw key string (missing translation) or is dead
|
||||
// weight (orphaned translation); this test fails loudly on either, per namespace.
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
const mods = import.meta.glob("./locales/*/*.json", { eager: true }) as Record<
|
||||
string,
|
||||
{ default: Record<string, unknown> }
|
||||
>;
|
||||
|
||||
function flatten(obj: Record<string, unknown>, prefix = ""): string[] {
|
||||
const out: string[] = [];
|
||||
for (const [k, v] of Object.entries(obj)) {
|
||||
const key = prefix ? `${prefix}.${k}` : k;
|
||||
if (v && typeof v === "object" && !Array.isArray(v)) {
|
||||
out.push(...flatten(v as Record<string, unknown>, key));
|
||||
} else {
|
||||
out.push(key);
|
||||
}
|
||||
}
|
||||
return out.sort();
|
||||
}
|
||||
|
||||
// { namespace: { en: {...}, hu: {...} } }
|
||||
const byNs: Record<string, Record<string, Record<string, unknown>>> = {};
|
||||
for (const [path, mod] of Object.entries(mods)) {
|
||||
const m = path.match(/\/locales\/([^/]+)\/([^/]+)\.json$/);
|
||||
const lang = m?.[1];
|
||||
const ns = m?.[2];
|
||||
if (!lang || !ns) continue;
|
||||
(byNs[ns] ??= {})[lang] = mod.default;
|
||||
}
|
||||
|
||||
describe("i18n en/hu key parity", () => {
|
||||
it("loaded both languages for every namespace", () => {
|
||||
expect(Object.keys(byNs).length).toBeGreaterThan(0);
|
||||
for (const [ns, langs] of Object.entries(byNs)) {
|
||||
expect({ ns, langs: Object.keys(langs).sort() }).toEqual({ ns, langs: ["en", "hu"] });
|
||||
}
|
||||
});
|
||||
|
||||
for (const [ns, langs] of Object.entries(byNs)) {
|
||||
it(`${ns}: en and hu declare identical keys`, () => {
|
||||
const en = flatten(langs.en ?? {});
|
||||
const hu = flatten(langs.hu ?? {});
|
||||
expect({
|
||||
missingInHu: en.filter((k) => !hu.includes(k)),
|
||||
missingInEn: hu.filter((k) => !en.includes(k)),
|
||||
}).toEqual({ missingInHu: [], missingInEn: [] });
|
||||
});
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user