feat: core components support simple locale switching (#4273)
* feat: core components support simple locale switching * fix: test error * fix: test error
This commit is contained in:
25
packages/@core/composables/src/use-simple-locale/index.ts
Normal file
25
packages/@core/composables/src/use-simple-locale/index.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
import { computed, ref } from 'vue';
|
||||
|
||||
import { createSharedComposable } from '@vueuse/core';
|
||||
|
||||
import { getMessages, type Locale } from './messages';
|
||||
|
||||
export const useSimpleLocale = createSharedComposable(() => {
|
||||
const currentLocale = ref<Locale>('zh-CN');
|
||||
|
||||
const setSimpleLocale = (locale: Locale) => {
|
||||
currentLocale.value = locale;
|
||||
};
|
||||
|
||||
const $t = computed(() => {
|
||||
const localeMessages = getMessages(currentLocale.value);
|
||||
return (key: string) => {
|
||||
return localeMessages[key] || key;
|
||||
};
|
||||
});
|
||||
return {
|
||||
$t,
|
||||
currentLocale,
|
||||
setSimpleLocale,
|
||||
};
|
||||
});
|
Reference in New Issue
Block a user