99 Guide ,
1010 DataAnalysis , Help , Setting
1111} from ' @element-plus/icons-vue'
12- import { ref , watch } from ' vue'
12+ import { ref , watch , getCurrentInstance } from ' vue'
1313import { API } from ' ./views/net'
1414import { Cache } from ' ./views/cache'
1515import TestingPanel from ' ./views/TestingPanel.vue'
@@ -21,8 +21,12 @@ import WelcomePage from './views/WelcomePage.vue'
2121import DataManager from ' ./views/DataManager.vue'
2222import MagicKey from ' ./components/MagicKey.vue'
2323import { useI18n } from ' vue-i18n'
24+ import ElementPlus from ' element-plus' ;
25+ import zhCn from ' element-plus/dist/locale/zh-cn.mjs'
26+ import enUS from ' element-plus/dist/locale/en.mjs'
2427
2528const { t, locale : i18nLocale } = useI18n ()
29+ const app = getCurrentInstance ()?.appContext .app ;
2630
2731import { setAsDarkTheme , getThemes , setTheme , getTheme } from ' ./theme'
2832
@@ -67,19 +71,25 @@ const handleSelect = (key: string) => {
6771const locale = ref (Cache .GetPreference ().language )
6872i18nLocale .value = locale .value
6973
70- watch (locale , (e : string ) => {
71- Cache .WithLocale (e )
72- i18nLocale .value = e
73- })
74+ watch (locale , (newLocale : string ) => {
75+ updateLocale (newLocale );
76+ });
77+ const updateLocale = (newLocale : string ) => {
78+ locale .value = newLocale ;
79+ i18nLocale .value = newLocale ;
80+ Cache .WithLocale (newLocale );
7481
82+ const elementLocale = newLocale === ' zh-CN' ? zhCn : enUS ;
83+ app ?.use (ElementPlus , { locale: elementLocale });
84+ };
7585const handleChangeLan = (command : string ) => {
7686 switch (command ) {
7787 case " chinese" :
78- locale .value = " zh-CN"
79- break ;
88+ locale .value = ' zh-CN' ;
89+ break ;
8090 case " english" :
81- locale .value = " en-US"
82- break ;
91+ locale .value = ' en-US' ;
92+ break ;
8393 }
8494};
8595
0 commit comments