refactor: refactor locales, separate locales within apps,fixed #12

This commit is contained in:
vben
2024-07-07 00:17:44 +08:00
parent 3571511394
commit 208d4188fc
77 changed files with 486 additions and 394 deletions

View File

@@ -2,13 +2,13 @@ import type { GeneratorMenuAndRoutesOptions } from '@vben/access';
import type { ComponentRecordType } from '@vben/types';
import { generateMenusAndRoutes } from '@vben/access';
import { $t } from '@vben/locales';
import { preferences } from '@vben-core/preferences';
import { message } from 'ant-design-vue';
import { getAllMenus } from '#/apis';
import { BasicLayout, IFrameView } from '#/layouts';
import { $t } from '#/locales';
const forbiddenPage = () => import('#/views/_essential/fallback/forbidden.vue');

View File

@@ -1,2 +1,2 @@
export * from './locale';
export * from './access';
export * from './request';

View File

@@ -1,48 +0,0 @@
import type { SupportedLanguagesType } from '@vben/types';
import type { Locale } from 'ant-design-vue/es/locale';
import { ref } from 'vue';
import defaultLocale from 'ant-design-vue/es/locale/zh_CN';
import dayjs from 'dayjs';
const antdLocale = ref<Locale>(defaultLocale);
async function loadDayjsLocale(lang: SupportedLanguagesType) {
let locale;
switch (lang) {
case 'zh-CN': {
locale = await import('dayjs/locale/zh-cn');
break;
}
case 'en-US': {
locale = await import('dayjs/locale/en');
break;
}
default: {
locale = await import('dayjs/locale/en');
} // 默认使用英语
}
dayjs.locale(locale);
}
async function loadAntdLocale(lang: SupportedLanguagesType) {
switch (lang) {
case 'zh-CN': {
antdLocale.value = defaultLocale;
break;
}
case 'en-US': {
antdLocale.value = (await import(
'ant-design-vue/es/locale/en_US'
)) as unknown as Locale;
break;
}
}
}
async function loadThirdPartyMessage(land: SupportedLanguagesType) {
await Promise.all([loadAntdLocale(land), loadDayjsLocale(land)]);
}
export { antdLocale, loadThirdPartyMessage };