feat: Support dayjs and component library in multiple languages

This commit is contained in:
vben
2024-06-30 15:42:30 +08:00
parent ca1cad0cd3
commit 1d70d71537
15 changed files with 99 additions and 20 deletions

View File

@@ -495,11 +495,12 @@
padding-right: 12px !important;
}
&:not(.is-active):hover {
// &:not(.is-active):hover {
&:hover {
color: var(--menu-submenu-hover-color);
text-decoration: none;
cursor: pointer;
background: var(--menu-submenu-hover-background-color);
background: var(--menu-submenu-hover-background-color) !important;
svg {
fill: var(--menu-submenu-hover-color);

View File

@@ -1 +1 @@
export { default as AuthPageLayoutType } from './authentication.vue';
export { default as AuthPageLayout } from './authentication.vue';

View File

@@ -43,7 +43,7 @@ function setI18nLanguage(locale: Locale) {
* Load locale messages
* @param lang
*/
async function loadLocaleMessages(lang: SupportedLanguagesType) {
async function loadI18nMessages(lang: SupportedLanguagesType) {
if (unref(i18n.global.locale) === lang) {
return setI18nLanguage(lang);
}
@@ -59,4 +59,4 @@ async function loadLocaleMessages(lang: SupportedLanguagesType) {
return setI18nLanguage(lang);
}
export { i18n, loadLocaleMessages, setI18nLanguage };
export { i18n, loadI18nMessages, setI18nLanguage };

View File

@@ -1,13 +1,22 @@
import type { LocaleSetupOptions } from './typing';
import type { LocaleSetupOptions, SupportedLanguagesType } from './typing';
import type { App } from 'vue';
import { i18n, loadLocaleMessages } from './i18n';
import { i18n, loadI18nMessages } from './i18n';
const $t = i18n.global.t;
let loadThirdPartyMessage: (lang: SupportedLanguagesType) => Promise<void>;
async function loadLocaleMessages(lang: SupportedLanguagesType) {
await loadI18nMessages(lang);
await loadThirdPartyMessage(lang);
}
async function setupI18n(app: App, options: LocaleSetupOptions = {}) {
const { defaultLocale = 'zh-CN' } = options;
// app可以自行扩展一些第三方库和组件库的国际化
loadThirdPartyMessage = options.loadThirdPartyMessage || (async () => {});
app.use(i18n);
await loadLocaleMessages(defaultLocale);
}

View File

@@ -8,6 +8,12 @@ interface LocaleSetupOptions {
* @default zh-CN
*/
defaultLocale?: SupportedLanguagesType;
/**
* Load third-party library messages
* @param lang
* @returns
*/
loadThirdPartyMessage?: (lang: SupportedLanguagesType) => Promise<void>;
}
export type { ImportLocaleFn, LocaleSetupOptions, SupportedLanguagesType };