diff --git a/src/i18n/index.ts b/src/i18n/index.ts index 8da071b..a3e8a7e 100644 --- a/src/i18n/index.ts +++ b/src/i18n/index.ts @@ -9,8 +9,21 @@ const messages = { "ja-JP": jaJP, }; +const supportedLocales = Object.keys(messages); + +const getInitialLocale = () => { + if (typeof window !== "undefined") { + const params = new URLSearchParams(window.location.search); + const lang = params.get("lang"); + if (lang && supportedLocales.includes(lang)) { + return lang; + } + } + return "zh-CN"; +}; + const i18n = createI18n({ - locale: 'zh-CN', + locale: getInitialLocale(), fallbackLocale: "zh-CN", messages, legacy: false, diff --git a/src/pages/file/index.vue b/src/pages/file/index.vue index 4f64943..4be8a4a 100644 --- a/src/pages/file/index.vue +++ b/src/pages/file/index.vue @@ -196,6 +196,9 @@ const { locale, t } = useI18n(); const handleLangMenuClick = ({ key }: { key: string }) => { locale.value = key; + const url = new URL(window.location.href); + url.searchParams.set("lang", key); + window.history.replaceState({}, "", url.href); }; const isPhone = ref(false); @@ -247,7 +250,12 @@ const requestCamera = () => { const shareUrl = async () => { if (myId.value) { const url = - window.location.origin + window.location.pathname + "?sign=" + myId.value; + window.location.origin + + window.location.pathname + + "?sign=" + + myId.value + + "&lang=" + + locale.value; await copyToClipboard(url); notification.success({ message: t("index.linkCopied"),