@aplus-frontend/ui
Version:
26 lines (25 loc) • 699 B
JavaScript
import { unref as r, computed as c, isRef as l, ref as s, inject as a } from "vue";
import { get as m } from "lodash-unified";
import "../../locale/index.mjs";
import i from "../../locale/lang/zh-cn.mjs";
const u = (t) => (e, o) => f(e, o, r(t)), f = (t, e, o) => m(o, t, t).replace(
/\{(\w+)\}/g,
(C, n) => `${e?.[n] ?? `{${n}}`}`
), p = (t) => {
const e = c(() => r(t).name), o = l(t) ? t : s(t);
return {
lang: e,
locale: o,
t: u(t)
};
}, x = Symbol("localeContextKey"), K = (t) => {
const e = t || a(x, s());
return p(c(() => e?.value || i));
};
export {
p as buildLocaleContext,
u as buildTranslator,
x as localeContextKey,
f as translate,
K as useLocale
};