Skip to content

Commit 2a1eaba

Browse files
committed
feat: use URL query to select language
1 parent eca7b95 commit 2a1eaba

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

app/components/home.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import { ServiceWorkerMLCEngine } from "@mlc-ai/web-llm";
1818
import MlcIcon from "../icons/mlc.svg";
1919
import LoadingIcon from "../icons/three-dots.svg";
2020

21-
import Locale from "../locales";
21+
import Locale, { changeLang, AllLangs, Lang } from "../locales";
2222
import { getCSSVar, useMobileScreen } from "../utils";
2323
import { DEFAULT_MODELS, Path, SlotID } from "../constant";
2424
import { ErrorBoundary } from "./error";

app/locales/index.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,16 @@ function getLanguage() {
104104
}
105105

106106
export function getLang(): Lang {
107+
if (typeof window !== "undefined") {
108+
const params = new URLSearchParams(window.location.search);
109+
if (
110+
params.get("lang") &&
111+
AllLangs.includes(params.get("lang")!.toLowerCase() as Lang)
112+
) {
113+
return params.get("lang") as Lang;
114+
}
115+
}
116+
107117
const savedLang = getItem(LANG_KEY);
108118

109119
if (AllLangs.includes((savedLang ?? "") as Lang)) {

0 commit comments

Comments
 (0)