//语言
// import { lang } from '@/settings/designSetting'
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: getStorage('language') || "ZH", // Default language
  fallbackLocale: "EN", // Fallback to English if translation missing
  messages: {
    ZH: zh,
    EN: en
  }
})

// Export function to change language
export function setLocale(lang) {
  if (['ZH', 'EN'].includes(lang)) {
    i18n.global.locale.value = lang
    setStorage('language', lang)
  }
}

export default i18n
