d-render
Version:
基于 Element Plus 二次封装的数据驱动渲染组件库 - 表单、搜索表单、表格配置化渲染
20 lines (17 loc) • 671 B
JavaScript
import { computed, unref, isRef, ref, inject } from 'vue';
import { buildTranslator, defaultLocale } from '../locale';
const localeContextKey = Symbol("drLocaleContextKey");
const buildLocaleContext = (locale) => {
const lang = computed(() => unref(locale).name);
const localeRef = isRef(locale) ? locale : ref(locale);
return {
lang,
locale: localeRef,
t: buildTranslator(() => unref(locale))
};
};
const useLocale = (localeOverrides) => {
const locale = localeOverrides || inject(localeContextKey, ref());
return buildLocaleContext(computed(() => locale.value || defaultLocale));
};
export { buildLocaleContext, localeContextKey, useLocale };