Skip to content

Commit

Permalink
🎨 (i18n) 优化关闭国际化功能时 antd 组件默认语言为中文
Browse files Browse the repository at this point in the history
  • Loading branch information
Hccake committed Jan 20, 2024
1 parent 3ff358e commit 5b990e2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { useI18n } from 'vue-i18n'
import { enableI18n } from '@/config'
import type { Locale } from 'ant-design-vue/es/locale-provider'
import type { Ref } from 'vue'
import dayjs from 'dayjs'
let antdLocal: Ref<Locale>
Expand All @@ -19,5 +20,13 @@ if (enableI18n) {
antdLocal = computed<Locale>(() => {
return i18n.getLocaleMessage(i18nStore.language)?.antdLocale as Locale
})
} else {
// 未开启国际化,默认使用中文
const modules = import.meta.glob('@/locales/lang/default-local-import.ts', { eager: true })
for (const path in modules) {
// @ts-ignore
antdLocal = modules[path].default
}
dayjs.locale('zh-cn')
}
</script>
4 changes: 4 additions & 0 deletions src/locales/lang/default-local-import.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import localeValues from 'ant-design-vue/es/locale/zh_CN'
import 'dayjs/locale/zh-cn'

export default localeValues

0 comments on commit 5b990e2

Please sign in to comment.