何时使用
- 登录、闪屏、rootRoute 门户等
- 无法读用户设置 store 的页面
- 已登录页改用 useLazyLocaleTranslation
签名
传入 LazyLocaleType 与显式 locale。
TSsignature
1function usePublicLazyLocaleTranslation(
2 locales: LazyLocaleType,
3 locale: "en-US" | "zh-CN" | "my-MM",
4): {
5 translation: {
6 get: (key: string, fallback?: string, data?: Record<string, unknown>) => string;
7 };
8 isLoading: boolean;
9 // …
10};用法
从 URL / 设备 / 公开偏好解析 locale,再加载对应 JSON。
TSXlogin
1import { usePublicLazyLocaleTranslation } from "@quan-erp/shared-ui";
2import { LoginLocaleLazy } from "./login.locale";
3
4export function LoginPage({ locale }: { locale: "en-US" | "zh-CN" | "my-MM" }) {
5 const { translation, isLoading } = usePublicLazyLocaleTranslation(
6 LoginLocaleLazy,
7 locale,
8 );
9
10 if (isLoading) return null;
11
12 return (
13 <button type="submit">
14 {translation.get("sign-in", "Sign in")}
15 </button>
16 );
17}注意
- 文件结构见 Core → Localization
- 同步 usePublicLocaleTranslation 为旧用法