File tree Expand file tree Collapse file tree 2 files changed +20
-14
lines changed
Expand file tree Collapse file tree 2 files changed +20
-14
lines changed Original file line number Diff line number Diff line change 11import type { createI18n } from "vue-i18n" ;
22type I18nOpt = Parameters < typeof createI18n > [ 0 ] ;
33
4+ const locale = ( ( ) => {
5+ if ( localStorage ) {
6+ const localLocale = localStorage . getItem ( "lang" ) ;
7+ const langStr = localLocale ?? navigator . language ;
8+ if ( langStr . startsWith ( "zh" ) ) return "zh-CN" ;
9+ if ( langStr . startsWith ( "en" ) ) return "en-US" ;
10+ }
11+ return "en-US" ;
12+ } ) ( ) ;
13+
14+ if ( localStorage && ! localStorage . getItem ( "lang" ) )
15+ localStorage . setItem ( "lang" , locale ) ;
16+
417export default {
518 legacy : false ,
6- locale : "zh-CN" ,
19+ locale,
720 messages : {
821 "zh-CN" : {
922 buttons : {
Original file line number Diff line number Diff line change 4646</template >
4747
4848<script setup lang="ts">
49- import { onMounted , watch } from " vue" ;
49+ import { watch } from " vue" ;
5050import { useI18n } from " vue-i18n" ;
5151
5252const { 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" ;
53+
54+ watch (locale , () => {
5855 document .documentElement .setAttribute (" lang" , locale .value );
59- watch (locale , () => {
60- document .documentElement .setAttribute (" lang" , locale .value );
61- localStorage .setItem (" lang" , locale .value );
62- });
56+ localStorage .setItem (" lang" , locale .value );
6357});
6458
6559import SIconLanguage from " @/ui/icons/language.vue" ;
6660import SIconGtihub from " @/ui/icons/github.vue" ;
6761import SIconAutoTheme from " @/ui/icons/autotheme.vue" ;
6862
69- function openGithub() {
63+ const openGithub = () =>
7064 window .open (" https://github.com/Linho1219/function-plot-GUI" );
71- }
7265
7366const emit = defineEmits ([" toggleDrawer" ]);
7467
75- import { useTheme } from " @/consts " ;
68+ import { useTheme } from " @/states " ;
7669const theme = useTheme ();
7770 </script >
7871
You can’t perform that action at this time.
0 commit comments