fix(presentation): persist the chosen locale in preferences (R-8.3)
The locale lived only in LocaleProvider state, so every remount (reload, or the scope fence after a session change) started again from ko-KR. The theme already persisted through preferences.setColorScheme; the locale now uses the same path (D-5): - contracts/storage-keys.ts: LOCALE key next to COLOR_SCHEME (localStorage, public-preference, opaque-string-v1). - application preferences port: additive getLocale()/setLocale(). The application treats the tag as opaque; presentation owns the locale list and normalizes what it reads back. - LocaleProvider: optional onLocaleChange; the provider stays storage-free so standalone uses and tests are unchanged. - AppRouter mounts LocaleProvider from the stored locale and persists changes (T46 moves this above the scope fence). Verified: RED "stores the chosen locale and starts the next mount from it" failed before (nothing written to LOCALE) and passes after. check:architecture, check:types:app, check:types:test, lint, test:component pass; check:registries PASS (compatibility unchanged from baseline); test:unit passes except the pre-existing removal-fixture test (needs generated artifacts/ files absent from a fresh worktree). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
b1a8269d65
commit
e5ef6ba236
@@ -74,9 +74,12 @@ const LocaleContext = createContext<LocaleContextValue>(DEFAULT_CONTEXT);
|
||||
export function LocaleProvider({
|
||||
children,
|
||||
initialLocale = "ko-KR",
|
||||
onLocaleChange,
|
||||
}: Readonly<{
|
||||
children: React.ReactNode;
|
||||
initialLocale?: SupportedLocale;
|
||||
/** Persists a user's choice; the provider itself stays storage-free. */
|
||||
onLocaleChange?: (locale: SupportedLocale) => void;
|
||||
}>) {
|
||||
const [locale, setLocaleState] = useState<SupportedLocale>(() =>
|
||||
normalizeLocale(initialLocale),
|
||||
@@ -92,7 +95,10 @@ export function LocaleProvider({
|
||||
() => ({
|
||||
locale,
|
||||
direction,
|
||||
setLocale: setLocaleState,
|
||||
setLocale(next) {
|
||||
setLocaleState(next);
|
||||
onLocaleChange?.(next);
|
||||
},
|
||||
message: (key, ...args) => formatMessage(locale, key, ...args),
|
||||
resolve: (key) => resolveMessage(locale, key),
|
||||
date: (dateValue, options) => formatDate(locale, dateValue, options),
|
||||
@@ -105,7 +111,7 @@ export function LocaleProvider({
|
||||
selectPlural(locale, pluralValue, choices),
|
||||
select: (selectValue, choices) => selectMessage(selectValue, choices),
|
||||
}),
|
||||
[direction, locale],
|
||||
[direction, locale, onLocaleChange],
|
||||
);
|
||||
|
||||
return (
|
||||
|
||||
@@ -39,10 +39,11 @@ import { ChunkRecoveryBoundary } from "../boundaries/chunk-recovery-boundary.tsx
|
||||
import { ContextErrorBoundary } from "../../platform/errors/context-error-boundary.tsx";
|
||||
import { FeatureErrorBoundary } from "../../platform/errors/feature-error-boundary.tsx";
|
||||
import { Button, PageHeader } from "../design-system/index.ts";
|
||||
import { LocaleProvider, useLocale } from "../i18n/index.ts";
|
||||
import { LocaleProvider, normalizeLocale, useLocale } from "../i18n/index.ts";
|
||||
import { AppShell } from "../layouts/app-shell.tsx";
|
||||
import {
|
||||
useApplicationDiagnostics,
|
||||
useApplicationPreferences,
|
||||
useApplicationRecovery,
|
||||
useApplicationRuntime,
|
||||
} from "../providers/application-provider.tsx";
|
||||
@@ -501,6 +502,7 @@ export function AppRouter({
|
||||
basename = "/",
|
||||
buildId = "local-build",
|
||||
}: Readonly<{ basename?: string; buildId?: string }>) {
|
||||
const preferences = useApplicationPreferences();
|
||||
const router = useMemo(
|
||||
() =>
|
||||
createBrowserRouter(createRegisteredRoutes(buildId), {
|
||||
@@ -509,7 +511,10 @@ export function AppRouter({
|
||||
[basename, buildId],
|
||||
);
|
||||
return (
|
||||
<LocaleProvider>
|
||||
<LocaleProvider
|
||||
initialLocale={normalizeLocale(preferences.getLocale() ?? "ko-KR")}
|
||||
onLocaleChange={preferences.setLocale}
|
||||
>
|
||||
<ThemeProvider>
|
||||
<SessionProvider>
|
||||
<RouterProvider router={router} />
|
||||
|
||||
Reference in New Issue
Block a user