完全跑通1.0版本
This commit is contained in:
22
frontend/node_modules/element-plus/es/hooks/use-locale/index.mjs
generated
vendored
Normal file
22
frontend/node_modules/element-plus/es/hooks/use-locale/index.mjs
generated
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
import en_default from "../../locale/lang/en.mjs";
|
||||
import { get } from "lodash-unified";
|
||||
import { computed, inject, isRef, ref, unref } from "vue";
|
||||
//#region ../../packages/hooks/use-locale/index.ts
|
||||
const buildTranslator = (locale) => (path, option) => translate(path, option, unref(locale));
|
||||
const translate = (path, option, locale) => get(locale, path, path).replace(/\{(\w+)\}/g, (_, key) => `${option?.[key] ?? `{${key}}`}`);
|
||||
const buildLocaleContext = (locale) => {
|
||||
return {
|
||||
lang: computed(() => unref(locale).name),
|
||||
locale: isRef(locale) ? locale : ref(locale),
|
||||
t: buildTranslator(locale)
|
||||
};
|
||||
};
|
||||
const localeContextKey = Symbol("localeContextKey");
|
||||
const useLocale = (localeOverrides) => {
|
||||
const locale = localeOverrides || inject(localeContextKey, ref());
|
||||
return buildLocaleContext(computed(() => locale.value || en_default));
|
||||
};
|
||||
//#endregion
|
||||
export { buildLocaleContext, buildTranslator, localeContextKey, translate, useLocale };
|
||||
|
||||
//# sourceMappingURL=index.mjs.map
|
||||
Reference in New Issue
Block a user