feat(housekeeping): localize content route headings
This commit is contained in:
1 parent
43470ebf82
commit
fc050bd3f8
14 files changed
+288
-30
No files matched your search
@@ -253,4 +253,70 @@ describe("housekeeping localization contract", () => {
|
||||
"Stiamo preparando gli strumenti di housekeeping disponibili.",
|
||||
);
|
||||
});
|
||||
it("keeps route-specific Content copy in the primary operator locales", () => {
|
||||
expect(en.pages.housekeeping.routes.content.editorial).toEqual({
|
||||
"article-create": "New article",
|
||||
"article-detail": "Edit article",
|
||||
articles: "Articles",
|
||||
tags: "Tags",
|
||||
"writeable-boxes": "Writable boxes",
|
||||
});
|
||||
expect(nl.pages.housekeeping.routes.content.editorial).toEqual({
|
||||
"article-create": "Nieuw artikel",
|
||||
"article-detail": "Artikel bewerken",
|
||||
articles: "Artikelen",
|
||||
tags: "Tags",
|
||||
"writeable-boxes": "Bewerkbare tekstblokken",
|
||||
});
|
||||
expect(itMessages.pages.housekeeping.routes.content.editorial).toEqual({
|
||||
"article-create": "Nuovo articolo",
|
||||
"article-detail": "Modifica articolo",
|
||||
articles: "Articoli",
|
||||
tags: "Tag",
|
||||
"writeable-boxes": "Riquadri modificabili",
|
||||
});
|
||||
});
|
||||
it("uses concrete Content workflow names across the primary operator locales", () => {
|
||||
const expectations = [
|
||||
[
|
||||
en,
|
||||
"New advertisement",
|
||||
"New event",
|
||||
"New help article",
|
||||
"Theme builder",
|
||||
"CMS translations",
|
||||
],
|
||||
[
|
||||
nl,
|
||||
"Nieuwe advertentie",
|
||||
"Nieuw evenement",
|
||||
"Nieuw helpartikel",
|
||||
"Thema-bouwer",
|
||||
"CMS-vertalingen",
|
||||
],
|
||||
[
|
||||
itMessages,
|
||||
"Nuova pubblicità",
|
||||
"Nuovo evento",
|
||||
"Nuovo articolo di assistenza",
|
||||
"Editor tema",
|
||||
"Traduzioni CMS",
|
||||
],
|
||||
] as const;
|
||||
for (const [
|
||||
messages,
|
||||
media,
|
||||
engagement,
|
||||
help,
|
||||
brand,
|
||||
localization,
|
||||
] of expectations) {
|
||||
const routes = messages.pages.housekeeping.routes.content;
|
||||
expect(routes.media["ad-create"]).toBe(media);
|
||||
expect(routes.engagement["event-create"]).toBe(engagement);
|
||||
expect(routes.help["question-create"]).toBe(help);
|
||||
expect(routes.brand["theme-builder"]).toBe(brand);
|
||||
expect(routes.localization.cms).toBe(localization);
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,55 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import type { HousekeepingRouteRenderInput } from "../routing/route-handler";
|
||||
import {
|
||||
resolveHousekeepingMessage,
|
||||
resolveHousekeepingRouteTitle,
|
||||
} from "./route-copy";
|
||||
|
||||
function input(
|
||||
translate?: (key: string) => string,
|
||||
): HousekeepingRouteRenderInput {
|
||||
return {
|
||||
context: {
|
||||
actor: { id: 42, username: "operator", rank: 7 },
|
||||
isSuperAdmin: false,
|
||||
has: () => true,
|
||||
hasAny: () => true,
|
||||
hasAll: () => true,
|
||||
},
|
||||
match: {
|
||||
routeId: "content.editorial.article-create",
|
||||
domain: "content",
|
||||
params: {},
|
||||
canonicalHref: "/ase-next/content/editorial/articles/new",
|
||||
},
|
||||
...(translate ? { translate } : {}),
|
||||
};
|
||||
}
|
||||
|
||||
describe("Housekeeping route copy", () => {
|
||||
it("resolves the localized title from the concrete route ID", () => {
|
||||
expect(
|
||||
resolveHousekeepingRouteTitle(
|
||||
input((key) =>
|
||||
key === "routes.content.editorial.article-create"
|
||||
? "New article"
|
||||
: key,
|
||||
),
|
||||
"Editorial content",
|
||||
),
|
||||
).toBe("New article");
|
||||
});
|
||||
|
||||
it("uses the explicit fallback when translation is absent or unresolved", () => {
|
||||
expect(resolveHousekeepingRouteTitle(input(), "Editorial content")).toBe(
|
||||
"Editorial content",
|
||||
);
|
||||
expect(
|
||||
resolveHousekeepingMessage(
|
||||
input((key) => key),
|
||||
"routes.content.editorial.article-create",
|
||||
"Editorial content",
|
||||
),
|
||||
).toBe("Editorial content");
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,21 @@
|
||||
import type { HousekeepingRouteRenderInput } from "../routing/route-handler";
|
||||
|
||||
export function resolveHousekeepingMessage(
|
||||
input: Pick<HousekeepingRouteRenderInput, "translate">,
|
||||
key: string,
|
||||
fallback: string,
|
||||
): string {
|
||||
const value = input.translate?.(key);
|
||||
return value && value !== key ? value : fallback;
|
||||
}
|
||||
|
||||
export function resolveHousekeepingRouteTitle(
|
||||
input: Pick<HousekeepingRouteRenderInput, "match" | "translate">,
|
||||
fallback: string,
|
||||
): string {
|
||||
return resolveHousekeepingMessage(
|
||||
input,
|
||||
`routes.${input.match.routeId}`,
|
||||
fallback,
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user