From 16bcce30b30f67dfb510f5cc201a2393789d4fda Mon Sep 17 00:00:00 2001 From: AkiChase <1003019131@qq.com> Date: Fri, 10 May 2024 17:13:36 +0800 Subject: [PATCH] feat(Setting): add language setting --- src/components/setting/Basic.vue | 28 +++++++++++++++++++++++++++- src/i18n/{en.json => en-US.json} | 0 src/i18n/index.ts | 10 +++++----- src/i18n/{zh.json => zh-CN.json} | 0 4 files changed, 32 insertions(+), 6 deletions(-) rename src/i18n/{en.json => en-US.json} (100%) rename src/i18n/{zh.json => zh-CN.json} (100%) diff --git a/src/components/setting/Basic.vue b/src/components/setting/Basic.vue index 778eb8a..c4fd319 100644 --- a/src/components/setting/Basic.vue +++ b/src/components/setting/Basic.vue @@ -13,9 +13,12 @@ import { useDialog, NCard, NIcon, + NFormItem, + NSelect, } from "naive-ui"; import { relaunch } from "@tauri-apps/plugin-process"; import { onMounted, ref } from "vue"; +import i18n from "../../i18n"; const localStore = new Store("store.bin"); const dialog = useDialog(); @@ -25,8 +28,16 @@ const showDataModal = ref(false); const dataModalInputVal = ref(""); let curDataIndex = -1; -onMounted(() => { +const languageOptions = [ + { label: "简体中文", value: "zh-CN" }, + { label: "English", value: "en-US" }, +]; + +const curLanguage = ref("en-US"); + +onMounted(async () => { refreshLocalData(); + curLanguage.value = (await localStore.get("language")) ?? "en-US"; }); async function refreshLocalData() { @@ -69,10 +80,25 @@ function delLocalStore(key?: string) { }); } } + +function changeLanguage(language: "zh-CN" | "en-US") { + if (language === curLanguage.value) return; + curLanguage.value = language; + localStore.set("language", language); + i18n.global.locale = language; +}