返回 CodeWhale
project.test.ts
根目录 / web / lib / i18n / project.test.ts
1 import { describe, expect, it } from "vitest";
2 import { locales } from "./config";
3 import { pickText } from "./dictionaries";
4 import { project as en } from "./dictionaries/en/project";
5 import { projectText } from "./project";
6 import { PROJECT_COPY, PROJECT_GOALS, CONTRIBUTION_ROUTES, STANDING_PROJECTS, PROJECT_RELEASES } from "../content/project";
7
8 describe("shared project translations", () => {
9 it("resolves every project string for each routed locale without dropping tokens", () => {
10 for (const key of Object.keys(en) as (keyof typeof en)[]) {
11 const text = projectText(key);
12 const tokens = en[key].match(/\{\w+\}/g)?.sort() ?? [];
13 for (const locale of locales) {
14 expect(text[locale], `${locale}.${key}`).toEqual(expect.any(String));
15 expect(pickText(text, locale), `${locale}.${key}`).toBe(text[locale]);
16 expect(text[locale]?.match(/\{\w+\}/g)?.sort() ?? [], `${locale}.${key}`).toEqual(tokens);
17 }
18 }
19 });
20
21 it("resolves page consumers through the same locale spine", () => {
22 const content = [PROJECT_COPY.goalsScope, PROJECT_GOALS[0].body, CONTRIBUTION_ROUTES[0].have, STANDING_PROJECTS[0].body, PROJECT_RELEASES[0].body];
23 for (const text of content) {
24 for (const locale of locales.filter(locale => locale !== "en")) {
25 expect(pickText(text, locale)).not.toBe(text.en);
26 }
27 }
28 expect(pickText({ en: "English", zh: "中文" }, "ja")).toBe("English");
29 expect(pickText(PROJECT_COPY.goalsScope, "unknown")).toBe(PROJECT_COPY.goalsScope.en);
30 });
31 });
32
32 lines TYPESCRIPT