feat: add localized home routes
This commit is contained in:
@@ -5,6 +5,7 @@ import React, {
|
||||
useMemo,
|
||||
useState,
|
||||
} from "react";
|
||||
import { languageForHomePathname } from "./languageRoutes";
|
||||
|
||||
export type Lang = "zh-CN" | "en" | "ja" | "ko" | "vi" | "id" | "ms";
|
||||
|
||||
@@ -372,6 +373,10 @@ const LANG_KEY = "ark_lang";
|
||||
|
||||
export function I18nProvider({ children }: { children: React.ReactNode }) {
|
||||
const [lang, setLangState] = useState<Lang>(() => {
|
||||
const routeLang = languageForHomePathname(window.location.pathname);
|
||||
if (routeLang) return routeLang;
|
||||
if (window.location.pathname === "/") return "en";
|
||||
|
||||
const s = localStorage.getItem(LANG_KEY);
|
||||
if (s === "zh" || s === "zh-TW") return "zh-CN";
|
||||
if (
|
||||
@@ -386,10 +391,10 @@ export function I18nProvider({ children }: { children: React.ReactNode }) {
|
||||
return s;
|
||||
return "en";
|
||||
});
|
||||
const setLang = (l: Lang) => {
|
||||
const setLang = useCallback((l: Lang) => {
|
||||
localStorage.setItem(LANG_KEY, l);
|
||||
setLangState(l);
|
||||
};
|
||||
}, []);
|
||||
const t = useCallback(
|
||||
(k: string) => dict[lang][k] || dict.en[k] || k,
|
||||
[lang],
|
||||
|
||||
Reference in New Issue
Block a user