Skip to content

Commit c2afe0b

Browse files
committed
语言选项记忆
1 parent c6b3f02 commit c2afe0b

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

src/i18n.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export default {
1919
confirm: "确定",
2020
language: "语言",
2121
repo: "GitHub 仓库",
22-
toogleTheme: '切换主题',
22+
toogleTheme: "切换主题",
2323
copy: "复制",
2424
undo: "撤销",
2525
},
@@ -75,7 +75,7 @@ export default {
7575
confirm: "Confirm",
7676
language: "Language",
7777
repo: "GitHub Repo",
78-
toogleTheme: 'Toggle Theme',
78+
toogleTheme: "Toggle Theme",
7979
copy: "Copy",
8080
undo: "Undo",
8181
},

src/ui/navbar.vue

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,19 +46,26 @@
4646
</template>
4747

4848
<script setup lang="ts">
49-
import { ref, watchEffect } from "vue";
49+
import { onMounted, watch } from "vue";
5050
import { useI18n } from "vue-i18n";
5151
5252
const { locale, t } = useI18n();
53+
onMounted(() => {
54+
const localLocale = localStorage.getItem("lang");
55+
const lang = localLocale ?? navigator.language;
56+
if (lang.startsWith("zh")) locale.value = "zh-CN";
57+
if (lang.startsWith("en")) locale.value = "en-US";
58+
document.documentElement.setAttribute("lang", locale.value);
59+
watch(locale, () => {
60+
document.documentElement.setAttribute("lang", locale.value);
61+
localStorage.setItem("lang", locale.value);
62+
});
63+
});
5364
5465
import SIconLanguage from "@/ui/icons/language.vue";
5566
import SIconGtihub from "@/ui/icons/github.vue";
5667
import SIconAutoTheme from "@/ui/icons/autotheme.vue";
5768
58-
const lang = ref("");
59-
60-
watchEffect(() => console.log(lang.value));
61-
6269
function openGithub() {
6370
window.open("https://github.com/Linho1219/function-plot-GUI");
6471
}

0 commit comments

Comments
 (0)