feat: add internationalization message platform

This commit is contained in:
donghyeon-ka
2026-07-26 16:17:39 +09:00
parent b8c0444217
commit 668bf05b48
57 changed files with 1711 additions and 201 deletions
+32 -14
View File
@@ -2,19 +2,22 @@ import { useId } from "react";
import { errorMessage } from "./error-copy.js";
import { Button } from "./ui/button.jsx";
import { useLocale } from "../i18n/index.js";
/** @param {{ label?: string }} props */
export function LoadingSurface({ label = "불러오는 중" }) {
export function LoadingSurface({ label }) {
const { message } = useLocale();
const accessibleLabel = label ?? message("async.loading");
return (
<section
className="state-surface state-surface--loading"
aria-busy="true"
aria-label={label}
aria-label={accessibleLabel}
aria-live="polite"
aria-atomic="true"
>
<div className="ui-skeleton" aria-hidden="true" />
<span className="visually-hidden">{label}</span>
<span className="visually-hidden">{accessibleLabel}</span>
</section>
);
}
@@ -27,13 +30,14 @@ export function LoadingSurface({ label = "불러오는 중" }) {
* }} props
*/
export function EmptySurface({
title = "표시할 항목이 없습니다.",
title,
description,
action,
}) {
const { message } = useLocale();
return (
<section className="ui-empty state-surface" aria-live="polite">
<h2>{title}</h2>
<h2>{title ?? message("async.empty")}</h2>
{description ? <p>{description}</p> : null}
{action}
</section>
@@ -49,13 +53,14 @@ export function EmptySurface({
* }} props
*/
export function TerminalErrorSurface({ userMessageKey, action, onAction }) {
const { locale, message } = useLocale();
const messageId = useId();
const actionLabels = Object.freeze({
retry: "다시 시도",
reauth: "로그인",
navigate: "안전한 화면으로 이동",
"reload-once": "한 번 새로고침",
"contact-support": "지원 정보 확인",
retry: message("action.retry"),
reauth: message("action.reauth"),
navigate: message("action.navigateSafe"),
"reload-once": message("action.reloadOnce"),
"contact-support": message("action.contactSupport"),
});
return (
<section
@@ -64,7 +69,7 @@ export function TerminalErrorSurface({ userMessageKey, action, onAction }) {
aria-labelledby={messageId}
data-message-key={userMessageKey}
>
<h2 id={messageId}>{errorMessage(userMessageKey)}</h2>
<h2 id={messageId}>{errorMessage(userMessageKey, locale)}</h2>
{action !== "none" && onAction && (
<Button onClick={onAction}>{actionLabels[action]}</Button>
)}
@@ -88,6 +93,7 @@ export function AsyncSurface({
onRetry,
onResolveConflict,
}) {
const { message } = useLocale();
if (state.base === "initial-loading") return <LoadingSurface />;
if (state.base === "empty") return <EmptySurface />;
if (state.base === "terminal-error" && state.failure) {
@@ -104,12 +110,24 @@ export function AsyncSurface({
<section aria-busy={state.overlay.refreshing || state.overlay.mutationPending}>
{state.indicator ? (
<div role="status" aria-live="polite">
<span>{state.indicator}</span>
<span>
{message(
state.indicator === "stale-degraded"
? "async.staleDegraded"
: state.indicator === "mutation-conflict"
? "async.mutationConflict"
: state.indicator === "mutation-pending"
? "async.mutationPending"
: "async.refreshing",
)}
</span>
{state.indicator === "stale-degraded" && onRetry ? (
<Button onClick={onRetry}>다시 시도</Button>
<Button onClick={onRetry}>{message("action.retry")}</Button>
) : null}
{state.indicator === "mutation-conflict" && onResolveConflict ? (
<Button onClick={onResolveConflict}>충돌 해결</Button>
<Button onClick={onResolveConflict}>
{message("action.resolveConflict")}
</Button>
) : null}
</div>
) : null}
+4 -24
View File
@@ -1,26 +1,6 @@
const ERROR_MESSAGES = Object.freeze({
"error.network_unreachable": "네트워크에 연결할 수 없습니다.",
"error.request_timeout": "요청 시간이 초과되었습니다.",
"error.auth_required": "계속하려면 로그인이 필요합니다.",
"error.auth_integration_failure": "로그인 연동을 사용할 수 없습니다.",
"error.forbidden": "이 작업을 수행할 권한이 없습니다.",
"error.not_found": "요청한 항목을 찾을 수 없습니다.",
"error.rate_limited": "요청이 많습니다. 잠시 후 다시 시도해 주세요.",
"error.server_failure": "요청을 완료하지 못했습니다.",
"error.chunk_load_failure": "새 화면 파일을 불러오지 못했습니다.",
"error.build_mismatch": "현재 화면과 활성 빌드가 일치하지 않습니다.",
"error.config_mismatch": "런타임 설정 버전이 현재 화면과 일치하지 않습니다.",
"error.api_contract_mismatch": "API 계약 버전이 현재 화면과 일치하지 않습니다.",
"error.release_mismatch": "현재 화면과 활성 릴리스가 일치하지 않습니다.",
"error.asset_mismatch": "화면 자산 구성이 현재 릴리스와 일치하지 않습니다.",
"error.render_failure": "화면을 표시하지 못했습니다.",
"error.unknown_failure": "예상하지 못한 문제가 발생했습니다.",
});
import { resolveMessage } from "../i18n/index.js";
/** @param {string} messageKey */
export function errorMessage(messageKey) {
const messages = /** @type {Readonly<Record<string, string>>} */ (
ERROR_MESSAGES
);
return messages[messageKey] ?? "요청을 완료하지 못했습니다.";
/** @param {string} messageKey @param {string} [locale] */
export function errorMessage(messageKey, locale = "ko-KR") {
return resolveMessage(locale, messageKey);
}
+16 -12
View File
@@ -1,4 +1,5 @@
import { Button } from "./ui/button.jsx";
import { useLocale } from "../i18n/index.js";
/**
* @param {{
@@ -30,12 +31,13 @@ function StateSurface({
/** @param {{ onSignIn?: () => void }} props */
export function AuthRequiredSurface({ onSignIn }) {
const { message } = useLocale();
return (
<StateSurface
eyebrow="401 · 인증 필요"
title="로그인이 필요합니다."
description="세션을 시작한 뒤 이전 작업을 안전하게 계속할 수 있습니다."
actionLabel="로그인 시작"
eyebrow={message("access.auth.eyebrow")}
title={message("access.auth.title")}
description={message("access.auth.description")}
actionLabel={message("action.signIn")}
onAction={onSignIn}
/>
);
@@ -43,12 +45,13 @@ export function AuthRequiredSurface({ onSignIn }) {
/** @param {{ onNavigate?: () => void }} props */
export function ForbiddenSurface({ onNavigate }) {
const { message } = useLocale();
return (
<StateSurface
eyebrow="403 · 권한 없음"
title="접근할 수 없습니다."
description="권한을 확인하거나 접근 가능한 화면으로 이동하세요."
actionLabel="안전한 화면으로 이동"
eyebrow={message("access.forbidden.eyebrow")}
title={message("access.forbidden.title")}
description={message("access.forbidden.description")}
actionLabel={message("action.navigateSafe")}
onAction={onNavigate}
tone="warning"
/>
@@ -57,12 +60,13 @@ export function ForbiddenSurface({ onNavigate }) {
/** @param {{ onNavigate?: () => void }} props */
export function NotFoundSurface({ onNavigate }) {
const { message } = useLocale();
return (
<StateSurface
eyebrow="404 · 찾을 수 없음"
title="요청한 화면이 없습니다."
description="주소를 확인하거나 시작 화면으로 돌아가세요."
actionLabel="시작 화면으로 이동"
eyebrow={message("access.notFound.eyebrow")}
title={message("access.notFound.title")}
description={message("access.notFound.description")}
actionLabel={message("action.goHome")}
onAction={onNavigate}
/>
);