feat(web): integrate localized application catalogs

- compose app, UI, and independently imported block catalogs from JSON configuration\n- persist the selected locale on the server and activate it without hydration flicker\n- add a flag-based language switcher and localized navigation descriptors\n- mount the redesigned i18n devtool only in development\n- regenerate English and Simplified Chinese catalogs and add switcher coverage
This commit is contained in:
Maofeng
2026-07-30 14:48:25 +08:00
parent 6af4d7b798
commit 8cf3a1f03a
19 changed files with 2474 additions and 135 deletions
@@ -0,0 +1,20 @@
import { createServerFn } from "@tanstack/react-start"
import { isAppLocale } from "@/i18n/app-locales"
import { readAppLocale, writeAppLocale } from "./app-locale.server"
export const getAppLocale = createServerFn({ method: "GET" }).handler(() => {
return readAppLocale()
})
export const setAppLocale = createServerFn({ method: "POST" })
.validator((value: unknown) => {
if (!isAppLocale(value)) {
throw new Error("Invalid app locale")
}
return value
})
.handler(({ data }) => {
writeAppLocale(data)
})
+25
View File
@@ -0,0 +1,25 @@
import "@tanstack/react-start/server-only"
import { getCookie, setCookie } from "@tanstack/react-start/server"
import {
DEFAULT_APP_LOCALE,
isAppLocale,
type AppLocale,
} from "@/i18n/app-locales"
const APP_LOCALE_COOKIE = "ui-locale"
const COOKIE_MAX_AGE = 60 * 60 * 24 * 365
export function readAppLocale(): AppLocale {
const locale = getCookie(APP_LOCALE_COOKIE)
return isAppLocale(locale) ? locale : DEFAULT_APP_LOCALE
}
export function writeAppLocale(locale: AppLocale) {
setCookie(APP_LOCALE_COOKIE, locale, {
maxAge: COOKIE_MAX_AGE,
path: "/",
sameSite: "lax",
})
}