화면 문구 셋이 어긋난다.
- 상태 화면 문구가 템플릿 개발자용이다(04-01). 생성 기능은 모두
`session-required`라 로그인 전 최종 사용자에게 "이 화면은 인증 연동 지점을
확인하기 위한 보호 라우트입니다."가 보인다. 끈 기능 화면은 "코드에는
포함되어 있으며 운영자가 다시 켤 수 있습니다.", 연동 실패 화면은 "외부 인증
소유자가 연결되면…"이다.
- 숫자를 locale formatter 없이 그린다(04-03). 생성 목록이 "총 12345개 항목"을
그리고, TextArea는 en에서 남은 1자도 "1 characters remaining"이다.
- ko·en 뜻이 다르다(04-07). en `form.conflict`에 "최신 상태를 확인해 주세요"가
없고, en 문서 제목 "Page not found"와 h1 "Page not found."가 다르다.
ErrorSummary가 번역 문장 사이에 JSX 글자 ": "를 넣는다.
고른 방법: 세 설명을 사용자 말("이 화면을 보려면 로그인해 주세요." 등)로 바꾸고
운영 설명은 뺐다. 생성 목록은 `useLocale().number(total)`을 넘긴다. TextArea는
`plural`로 `form.remaining.one`(en 단수)과 `form.remaining`을 고른다. en 충돌
문구에 행동을 더하고 not-found 제목을 h1과 같게 했다. 오류 요약 항목은
`form.errorSummary.item` "{label}: {message}"로 잇는다. 연동 실패 화면의 제목
"로그인 연동이 필요합니다."는 짝 백엔드 매뉴얼이 그 글자로 가리켜 그대로 뒀다.
검증 V4가 반박한 부분(세 화면에 행동 버튼이 없다, ProgressBar `%`)은 고치지
않았다: 셸 탐색이 늘 있고, `%`는 ko·en 결과가 같다.
위험·한계: 다운스트림이 이 키의 옛 문장을 시험으로 고정했으면 문장을 바꾼다.
이미 생성한 기능의 목록 페이지는 `count: query.data.total`을 그대로 갖는다.
`number(query.data.total)`로 바꾸면 된다(생성 명령의 새 출력과 같다).
검증: `tests/unit/i18n-contract.test.ts`(개발자 낱말, not-found 제목, 항목
문장), `tests/component/design-system-a11y.test.tsx`(en 단수·복수),
`tests/unit/create-feature.test.ts`(생성 목록의 `number(`)가 고치기 전에
실패하고 고친 뒤 통과한다. 생성 기능 시험의 total 12345 → "총 12,345개 항목"은
FE-GATE-005가 돌린다(desktop, PR 본문).
Refs: 1112/04-01, 1112/04-03, 1112/04-07
165 lines
5.4 KiB
TypeScript
165 lines
5.4 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
||
|
||
import { ERROR_REGISTRY } from "../../src/contracts/errors.ts";
|
||
|
||
import {
|
||
catalogKeys,
|
||
FORMAT_FALLBACK,
|
||
formatDate,
|
||
formatList,
|
||
formatMessage,
|
||
formatNumber,
|
||
formatRelativeTime,
|
||
localeDirection,
|
||
messagePlaceholders,
|
||
normalizeLocale,
|
||
resolveMessage,
|
||
selectMessage,
|
||
selectPlural,
|
||
} from "../../src/presentation/i18n/index.ts";
|
||
import {
|
||
EN_MESSAGES,
|
||
KO_MESSAGES,
|
||
MESSAGE_CATALOGS,
|
||
} from "../../src/presentation/i18n/catalog.ts";
|
||
|
||
describe("internationalization message contract", () => {
|
||
it("keeps every registered catalog and interpolation contract in parity", () => {
|
||
expect(catalogKeys("en-US")).toEqual(catalogKeys("ko-KR"));
|
||
expect(catalogKeys("ar-EG")).toEqual(catalogKeys("ko-KR"));
|
||
|
||
for (const key of catalogKeys("ko-KR")) {
|
||
expect(messagePlaceholders(EN_MESSAGES[key])).toEqual(
|
||
messagePlaceholders(KO_MESSAGES[key]),
|
||
);
|
||
}
|
||
expect(MESSAGE_CATALOGS["ar-EG"]).toBe(EN_MESSAGES);
|
||
});
|
||
|
||
// 07-01/08-02. A kind without copy renders "This message is unavailable."
|
||
// as the failure title, so every registry row must resolve in both locales.
|
||
it("gives every error registry kind its own message in every locale", () => {
|
||
const missing = Object.values(ERROR_REGISTRY).flatMap((definition) =>
|
||
[KO_MESSAGES, EN_MESSAGES]
|
||
.filter((catalog) => !Object.hasOwn(catalog, definition.userMessageKey))
|
||
.map(() => definition.userMessageKey),
|
||
);
|
||
expect(missing).toEqual([]);
|
||
});
|
||
|
||
it("formats typed parameters and expands the pseudo locale", () => {
|
||
expect(
|
||
formatMessage("en-US", "route.documentTitle", {
|
||
title: "Settings",
|
||
appName: "Skeleton",
|
||
}),
|
||
).toBe("Settings · Skeleton");
|
||
const pseudo = formatMessage("en-XA", "action.closeNamed", {
|
||
title: "Account",
|
||
});
|
||
expect(pseudo).toMatch(/^[.+ ···]$/);
|
||
expect(pseudo.length).toBeGreaterThan("Close Account".length);
|
||
});
|
||
|
||
it("falls back safely for unknown locale, key and missing interpolation", () => {
|
||
expect(normalizeLocale("fr-FR")).toBe("ko-KR");
|
||
expect(resolveMessage("fr-FR", "action.retry")).toBe("다시 시도");
|
||
expect(resolveMessage("en-US", "action.login")).toBe("Sign in");
|
||
// The fallback copy follows the requested locale.
|
||
expect(resolveMessage("en-US", "backend.stack.trace")).toBe(
|
||
"This message is unavailable.",
|
||
);
|
||
expect(resolveMessage("en-US", "action.closeNamed")).toBe(
|
||
"This message is unavailable.",
|
||
);
|
||
expect(resolveMessage("ko-KR", "backend.stack.trace")).toBe(
|
||
"요청한 문구를 표시할 수 없습니다.",
|
||
);
|
||
expect(resolveMessage("en-US", "backend.stack.trace")).not.toContain(
|
||
"backend.stack.trace",
|
||
);
|
||
});
|
||
|
||
it("defines direction without inferring it in components", () => {
|
||
expect(localeDirection("ko-KR")).toBe("ltr");
|
||
expect(localeDirection("en-XA")).toBe("ltr");
|
||
expect(localeDirection("ar-EG")).toBe("rtl");
|
||
});
|
||
});
|
||
|
||
describe("internationalization formatter contract", () => {
|
||
const instant = new Date("2026-07-26T23:30:00.000Z");
|
||
|
||
it("uses an explicit UTC default and deterministic locale formatting", () => {
|
||
expect(formatDate("en-US", instant, { dateStyle: "short" })).toBe(
|
||
"7/26/26",
|
||
);
|
||
expect(
|
||
formatDate("en-US", instant, {
|
||
dateStyle: "short",
|
||
timeZone: "Asia/Seoul",
|
||
}),
|
||
).toBe("7/27/26");
|
||
expect(formatNumber("en-US", 1234.5)).toBe("1,234.5");
|
||
expect(formatRelativeTime("en-US", -1, "day")).toBe("yesterday");
|
||
expect(formatList("en-US", ["one", "two", "three"])).toBe(
|
||
"one, two, and three",
|
||
);
|
||
expect(selectPlural("en-US", 1, { one: "item", other: "items" })).toBe(
|
||
"item",
|
||
);
|
||
expect(
|
||
selectPlural("en-US", 3, { one: "item", other: "items" }),
|
||
).toBe("items");
|
||
expect(
|
||
selectMessage("pending", {
|
||
ready: "Ready",
|
||
pending: "Pending",
|
||
other: "Unknown",
|
||
}),
|
||
).toBe("Pending");
|
||
});
|
||
|
||
it("does not throw or expose invalid formatter input", () => {
|
||
expect(formatDate("en-US", Number.NaN)).toBe(FORMAT_FALLBACK);
|
||
expect(formatNumber("en-US", Number.POSITIVE_INFINITY)).toBe(
|
||
FORMAT_FALLBACK,
|
||
);
|
||
expect(
|
||
formatDate("en-US", instant, { timeZone: "not/a-time-zone" }),
|
||
).toBe(FORMAT_FALLBACK);
|
||
});
|
||
});
|
||
|
||
// 1112/04-01, 04-07. Copy an end user reads on the platform status surfaces.
|
||
describe("platform status copy", () => {
|
||
const ENGLISH_AND_KOREAN = [KO_MESSAGES, EN_MESSAGES] as const;
|
||
|
||
it("does not explain the template to the end user on status surfaces", () => {
|
||
const developerWords =
|
||
/라우트|연동 지점|seam|코드에는 포함|운영자|operator|protected route|this build/iu;
|
||
for (const catalog of ENGLISH_AND_KOREAN) {
|
||
for (const key of [
|
||
"route.auth.required.description",
|
||
"route.auth.integration.description",
|
||
"route.disabledFeature.description",
|
||
] as const) {
|
||
expect(catalog[key], key).not.toMatch(developerWords);
|
||
}
|
||
}
|
||
});
|
||
|
||
it("titles the not-found document the same as its heading", () => {
|
||
for (const catalog of ENGLISH_AND_KOREAN) {
|
||
expect(catalog["route.NOT_FOUND.title"]).toBe(catalog["page.notFound.title"]);
|
||
}
|
||
});
|
||
|
||
it("joins an error summary entry through the catalog", () => {
|
||
expect(formatMessage("en-US", "form.errorSummary.item", {
|
||
label: "Name",
|
||
message: "Required.",
|
||
})).toBe("Name: Required.");
|
||
});
|
||
});
|