This commit is contained in:
小吾立 2024-06-19 10:09:01 +08:00
parent 919596914f
commit 6510926861
4 changed files with 2823 additions and 5018 deletions

View File

@ -39,6 +39,7 @@
},
"devDependencies": {
"@types/node": "^20.10.8",
"@types/vue-i18n": "^7.0.0",
"@typescript-eslint/eslint-plugin": "^6.18.1",
"@typescript-eslint/parser": "^6.18.1",
"@vitejs/plugin-vue": "^5.0.4",

View File

@ -25,16 +25,18 @@ export const langDict: { [key: string]: LangType } = {
local: () => import(/* @vite-ignore */ './locales/en_us.json')
}
}
export const defaultLocale = 'zh-cn'
const i18n = createI18n<Record<string, any>>({
legacy: false,
// locale: 'zh-cn', // 默认显示语言
locale: defaultLocale, // 默认显示语言
fallbackLocale: defaultLocale, // 默认显示语言
warnHtmlMessage: false
})
export const changeLang = async (langKey: string) => {
langKey = langKey.toLowerCase()
const lang = langDict[langKey || 'zh-cn']
const lang = langDict[langKey || defaultLocale]
await loadLanguageAsync(langKey, lang)
return await lang.antd()
}
@ -60,8 +62,18 @@ export const supportLang = [
label: '\u7b80\u4f53\u4e2d\u6587',
value: 'zh-cn'
},
{
label: '\u7e41\u4f53\u4e2d\u6587\uff08\u4e2d\u56fd\u9999\u6e2f\uff09',
value: 'zh-hk'
},
{
label: '\u7e41\u4f53\u4e2d\u6587\uff08\u4e2d\u56fd\u53f0\u6e7e\uff09',
value: 'zh-tw'
},
{
label: 'English',
value: 'en-us'
}
]
export const supportLangArray = supportLang.map((item) => item.value)

File diff suppressed because it is too large Load Diff

View File

@ -1,4 +1,4 @@
import { t } from '@/i18n'
import { t, supportLangArray, defaultLocale } from '@/i18n'
///
/// Copyright (c) 2019 Of Him Code Technology Studio
/// Jpom is licensed under Mulan PSL v2.
@ -264,13 +264,13 @@ export const useGuideStore = defineStore('guide', {
},
getLocale: (state) => {
return () => {
const locale = state.guideCache.locale || navigator.language
const array = ['zh-cn', 'en-us', 'zh_cn', 'en_us']
if (array.includes(locale.toLowerCase())) {
let locale = state.guideCache.locale || navigator.language
locale = locale.replace('_', '-')
if (supportLangArray.includes(locale.toLowerCase())) {
// 避免非法字符串
return locale
}
return 'zh-cn'
return defaultLocale
}
}
}