import en_default from "../../locale/lang/en.mjs";
import { inject, ref, computed, isRef, unref } from "vue";
import get from "../../../../lodash-es/get.mjs";
const buildTranslator = (locale) => (path, option) => translate(path, option, unref(locale));
const translate = (path, option, locale) => get(locale, path, path).replace(/\{(\w+)\}/g, (_, key) => `${(option == null ? void 0 : 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));
};
export {
  buildLocaleContext,
  buildTranslator,
  localeContextKey,
  translate,
  useLocale
};
