10.10综合交易所原始源码_移动端
1
admin
2026-02-01 00895f4da2b9fd7e0e66096815085528baa6299e
src/i18n/index.js
@@ -1,5 +1,5 @@
import { createI18n } from 'vue-i18n'
import { getStorage } from '@/utils/index'
import { getStorage, getBrowserLang } from '@/utils/index'
import enLocale from './modules/en'
import cnLocale from './modules/CN'
import zhcnLocale from './modules/zh-CN'
@@ -13,56 +13,42 @@
import Italy from './modules/Italy'
import SpanishLocal from './modules/es'
import PortugueseLocal from './modules/pt'
const lang = getStorage('lang') || 'en'
const messages = {
  'en': {
    ...enLocale
  },
  'CN': {
    ...cnLocale
  },
  'zh-CN': {
    ...zhcnLocale
  },
  'Korean': {
    ...korcnLocale
  },
  'Japanese': {
    ...japcnLocale
  },
  'de': {
    ...Deutsch
  },
  'fr': {
    ...fr
  },
  'vi': {
    ...vi
  },
  'th': {
    ...th
  },
  'Italy': {
    ...Italy
  },
  'es': {
    ...SpanishLocal
  },
  'pt': {
    ...PortugueseLocal
  },
  'gr': {
    ...gr
  }
// 支持的 locale 列表,用于校验
const SUPPORTED_LOCALES = ['en', 'CN', 'zh-CN', 'Korean', 'Japanese', 'de', 'fr', 'vi', 'th', 'Italy', 'es', 'pt', 'gr']
// 获取初始语言:缓存 > 浏览器语言,并确保在支持列表中
function getInitialLocale() {
  const cached = getStorage('lang')
  if (cached && SUPPORTED_LOCALES.includes(cached)) return cached
  const browserLang = getBrowserLang()
  return SUPPORTED_LOCALES.includes(browserLang) ? browserLang : 'en'
}
const messages = {
  en: { ...enLocale },
  CN: { ...cnLocale },
  'zh-CN': { ...zhcnLocale },
  Korean: { ...korcnLocale },
  Japanese: { ...japcnLocale },
  de: { ...Deutsch },
  fr: { ...fr },
  vi: { ...vi },
  th: { ...th },
  Italy: { ...Italy },
  es: { ...SpanishLocal },
  pt: { ...PortugueseLocal },
  gr: { ...gr }
}
const i18n = createI18n({
  legacy: false,
  locale: lang, // 首先从缓存里拿,没有的话就用浏览器语言,
  fallbackLocale: 'en', // 设置备用语言
  locale: getInitialLocale(),
  fallbackLocale: ['zh-CN', 'en'], // 缺失 key 时先回退到简体中文,再回退到英文
  messages,
  missingWarn: import.meta.env.DEV, // 仅开发环境输出缺失 key 警告
  fallbackWarn: import.meta.env.DEV,
  silentTranslationWarn: !import.meta.env.DEV
})
export default i18n