mirror of
https://github.com/vbenjs/vue-vben-admin.git
synced 2025-08-26 16:46:19 +08:00
feat: multi-language layout
This commit is contained in:
@@ -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
21
src/hooks/web/useI18n.ts
Normal 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);
|
||||
},
|
||||
};
|
||||
}
|
@@ -65,10 +65,3 @@ export function useLocale() {
|
||||
antConfigLocale: antConfigLocaleRef,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* For non-setup setting
|
||||
*/
|
||||
export function useExternalI18n() {
|
||||
return getI18n().global;
|
||||
}
|
||||
|
Reference in New Issue
Block a user