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
@@ -16,6 +16,9 @@ import {
|
||||
useLocale,
|
||||
type SupportedLocale,
|
||||
} from "../../src/presentation/i18n/index.ts";
|
||||
import { ApplicationProvider } from "../../src/presentation/providers/application-provider.tsx";
|
||||
import { AppRouter } from "../../src/presentation/routes/app-router.tsx";
|
||||
import { createTestApplication } from "../helpers/create-test-application.ts";
|
||||
|
||||
function LocaleHarness() {
|
||||
const { direction, locale, message, setLocale } = useLocale();
|
||||
@@ -118,3 +121,39 @@ describe("locale provider runtime", () => {
|
||||
expect(screen.queryByRole("img")).not.toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
||||
describe("persisted locale preference", () => {
|
||||
it("stores the chosen locale and starts the next mount from it", async () => {
|
||||
const user = userEvent.setup();
|
||||
const stored = new Map<string, unknown>();
|
||||
const application = createTestApplication({
|
||||
preferences: {
|
||||
read: (name) => ({ ok: true as const, value: stored.get(name) }),
|
||||
write: (name, value) => {
|
||||
stored.set(name, value);
|
||||
return { ok: true as const };
|
||||
},
|
||||
remove: (name) => {
|
||||
stored.delete(name);
|
||||
return { ok: true as const };
|
||||
},
|
||||
},
|
||||
});
|
||||
const mount = () =>
|
||||
render(
|
||||
<ApplicationProvider application={application}>
|
||||
<AppRouter />
|
||||
</ApplicationProvider>,
|
||||
);
|
||||
window.history.pushState({}, "", "/missing");
|
||||
|
||||
const first = mount();
|
||||
await user.selectOptions(await screen.findByLabelText("언어"), "en-US");
|
||||
expect(stored.get("LOCALE")).toBe("en-US");
|
||||
first.unmount();
|
||||
|
||||
mount();
|
||||
expect(await screen.findByLabelText("Language")).toHaveValue("en-US");
|
||||
expect(document.documentElement).toHaveAttribute("lang", "en-US");
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user