mirror of
https://gitee.com/dromara/Jpom.git
synced 2024-12-02 03:48:05 +08:00
fix i18n
This commit is contained in:
parent
919596914f
commit
6510926861
@ -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",
|
||||
|
@ -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
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user