feat: multi-language layout

This commit is contained in:
vben
2020-11-25 23:20:30 +08:00
parent cedba37e4c
commit e5f8ce3fd8
44 changed files with 504 additions and 386 deletions

View File

@@ -19,10 +19,20 @@ export function useLocaleSetting() {
// get Fallback Locales
const getFallbackLocale = computed((): string => unref(getLocale).fallback);
const getShowLocale = computed(() => unref(getLocale).show);
// Set locale configuration
function setLocale(locale: Partial<LocaleSetting>): void {
appStore.commitProjectConfigState({ locale });
}
return { getLocale, getLang, localeList, setLocale, getAvailableLocales, getFallbackLocale };
return {
getLocale,
getLang,
localeList,
setLocale,
getShowLocale,
getAvailableLocales,
getFallbackLocale,
};
}

21
src/hooks/web/useI18n.ts Normal file
View File

@@ -0,0 +1,21 @@
import { getI18n } from '/@/setup/i18n';
export function useI18n(namespace?: string) {
const { t, ...methods } = getI18n().global;
function getKey(key: string) {
if (!namespace) {
return key;
}
if (key.startsWith(namespace)) {
return key;
}
return `${namespace}.${key}`;
}
return {
...methods,
t: (key: string, ...arg: Parameters<typeof t>) => {
return t(getKey(key), ...arg);
},
};
}

View File

@@ -65,10 +65,3 @@ export function useLocale() {
antConfigLocale: antConfigLocaleRef,
};
}
/**
* For non-setup setting
*/
export function useExternalI18n() {
return getI18n().global;
}