feat(i18n): the server's closed English vocabularies named in the reader's language (E30 S2)
- lib/vocab + the `vocab` locale area: TMDB crew jobs and departments, auto-tags (D1 A: the data
stays English, the catalog is named at its one source, useTags), built-in download profiles,
YouTube topics; held key-for-key to the backend's own lists by backendIds.contract.
- Countries by ISO code: TMDB parse stores {code, name}; rows stored before are coded from TMDB's
own country list in one request (run_enrich); Intl names them, historic codes (YU, SU, XI…)
from the catalog.
- Player tracks named from the language tag, forced/SDH flags and codec tail, not Plex's
server-language displayTitle; no invented "Audio N" on the server.
- Download lifecycle notices (shared / expiring / expired / evicted) named from data; the share
notice carries the title.
- Scheduler: the job result rides along as data and is named per key (dashboard + run notice).
- Invite status named; a render crash's notice no longer shows the engine's English message.
- Fix: YouTube links …/wiki/Humour, the tagger looked for "Humor" — Comedy never came from a topic.
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import { readdirSync, readFileSync } from "node:fs";
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { vocabKey } from "../lib/vocab";
|
||||
|
||||
// Every id the BACKEND owns and the UI names must have its name in both languages. The UI looks these
|
||||
// up with the raw id as the fallback — `t(\`config.fields.${key}.label\`, key)` — so a missing key never
|
||||
@@ -147,6 +148,45 @@ const youtubeReasons = [
|
||||
).matchAll(/"(\w+)"/g),
|
||||
].map((m) => m[1]!);
|
||||
|
||||
// E30: the closed English vocabularies the backend WRITES into data, named through `vocab.<group>`
|
||||
// (lib/vocab) by their letters-and-digits key. A word the backend adds shows in English until named —
|
||||
// so each list is read from its source here: the TMDB crew jobs kept, every auto-tag the tagger can
|
||||
// create, and the built-in download profiles of the latest migration that seeds them.
|
||||
const pyStrings = (block: string | undefined, re: RegExp) =>
|
||||
[...(block ?? "").matchAll(re)].map((m) => m[1]!);
|
||||
const between = (src: string, start: string, end: string) => src.split(start)[1]?.split(end)[0];
|
||||
const tmdbPy = backend("plex/tmdb.py");
|
||||
const crewJobs = [
|
||||
...new Set([
|
||||
...pyStrings(between(tmdbPy, "_MOVIE_CREW_JOBS = (", ")"), /"([^"]+)"/g),
|
||||
...pyStrings(between(tmdbPy, "_TV_CREW_JOBS = (", ")"), /"([^"]+)"/g),
|
||||
]),
|
||||
];
|
||||
const autotagPy = backend("sync/autotag.py");
|
||||
const autoTags = [
|
||||
...new Set([
|
||||
...pyStrings(between(autotagPy, "LANG_NAMES = {", "}"), /:\s*"([^"]+)"/g),
|
||||
...pyStrings(between(autotagPy, "TOPIC_COLORS = {", "}"), /"([^"]+)":/g),
|
||||
...pyStrings(between(autotagPy, "_TOPIC_SLUGS = {", "}"), /:\s*"([^"]+)"/g),
|
||||
...pyStrings(between(autotagPy, "_CATEGORY_NAMES = {", "}"), /:\s*"([^"]+)"/g),
|
||||
...pyStrings(between(autotagPy, "def map_topic_slug", "\n\n\n"), /return "([^"]+)"/g),
|
||||
]),
|
||||
];
|
||||
const migrations = readdirSync(new URL("../../../backend/alembic/versions/", import.meta.url))
|
||||
.filter((f) => f.endsWith(".py"))
|
||||
.sort();
|
||||
const seeding = migrations
|
||||
.map((f) =>
|
||||
readFileSync(new URL(`../../../backend/alembic/versions/${f}`, import.meta.url), "utf-8"),
|
||||
)
|
||||
.filter((src) => src.includes("_BUILTINS = ["))
|
||||
.pop();
|
||||
const builtinProfiles = pyStrings(
|
||||
between(seeding ?? "", "_BUILTINS = [", "\n]"),
|
||||
/^\s+\("([^"]+)",/gm,
|
||||
);
|
||||
const VOCAB = { crewJob: crewJobs, autoTag: autoTags, profile: builtinProfiles };
|
||||
|
||||
/** The ids under `prefix` a locale names, `prefix.<id>` or `prefix.<id>.<anything>`. */
|
||||
const idsUnder = (keys: Set<string>, prefix: string) =>
|
||||
new Set(
|
||||
@@ -170,6 +210,13 @@ describe("backend ids have their names in both languages", () => {
|
||||
expect(goneWhats).toEqual(expect.arrayContaining(["playlist", "download", "job"]));
|
||||
expect(opaqueWhats).toEqual([]);
|
||||
expect(youtubeReasons).toEqual(["quota", "reconnect", "unavailable"]);
|
||||
expect(crewJobs).toEqual(
|
||||
expect.arrayContaining(["Director", "Creator", "Director of Photography"]),
|
||||
);
|
||||
expect(autoTags).toEqual(
|
||||
expect.arrayContaining(["English", "Gaming", "Health & Fitness", "Hobbies", "Sports"]),
|
||||
);
|
||||
expect(builtinProfiles).toEqual(expect.arrayContaining(["720p (MP4)", "Video only (MP4)"]));
|
||||
expect(refusedReasons).toEqual(
|
||||
expect.arrayContaining(["weak_password", "setting_too_low", "plex_write_failed"]),
|
||||
);
|
||||
@@ -254,6 +301,17 @@ describe("backend ids have their names in both languages", () => {
|
||||
).toEqual([]);
|
||||
});
|
||||
|
||||
it(`${lang}: every crew job, auto-tag and built-in profile the backend writes, and no other`, () => {
|
||||
for (const [group, words] of Object.entries(VOCAB)) {
|
||||
const wanted = words.map((w) => `vocab.${group}.${vocabKey(w)}`);
|
||||
expect(missing(wanted), group).toEqual([]);
|
||||
expect(
|
||||
[...keys].filter((k) => k.startsWith(`vocab.${group}.`) && !wanted.includes(k)),
|
||||
group,
|
||||
).toEqual([]);
|
||||
}
|
||||
});
|
||||
|
||||
it(`${lang}: every admin refusal reason`, () => {
|
||||
expect(missing(adminReasons.map((r) => `errors.admin.${r}`))).toEqual([]);
|
||||
expect([...idsUnder(keys, "errors.admin")].filter((r) => !adminReasons.includes(r))).toEqual(
|
||||
|
||||
Reference in New Issue
Block a user