优化代码
This commit is contained in:
@@ -3,11 +3,12 @@
|
||||
import { createI18n } from 'vue-i18n' //引入vue-i18n组件
|
||||
import zh from './zh/index'
|
||||
import en from './en/index'
|
||||
import { setStorage , getStorage } from '@/utils/storage.js';
|
||||
|
||||
const i18n = createI18n({
|
||||
legacy: false,
|
||||
globalInjection:true,
|
||||
locale: "ZH", // Default language
|
||||
locale: getStorage('language') || "ZH", // Default language
|
||||
fallbackLocale: "EN", // Fallback to English if translation missing
|
||||
messages: {
|
||||
ZH: zh,
|
||||
@@ -19,7 +20,8 @@ const i18n = createI18n({
|
||||
export function setLocale(lang) {
|
||||
if (['ZH', 'EN'].includes(lang)) {
|
||||
i18n.global.locale.value = lang
|
||||
setStorage('language', lang)
|
||||
}
|
||||
}
|
||||
|
||||
export default i18n
|
||||
export default i18n
|
||||
|
||||
Reference in New Issue
Block a user