'use strict';

var zhCn = require('../../locale/lang/zh-cn.js');
var lodashEs = require('lodash-es');
var vue = require('vue');

"use strict";
const buildTranslator = (locale) => (path, option) => translate(path, option, vue.unref(locale));
const translate = (path, option, locale) => lodashEs.get(locale, path, path).replace(
  /\{(\w+)\}/g,
  (_, key) => `${option?.[key] ?? `{${key}}`}`
);
const buildLocaleContext = (locale) => {
  const lang = vue.computed(() => vue.unref(locale).name);
  const localeRef = vue.isRef(locale) ? locale : vue.ref(locale);
  return {
    lang,
    locale: localeRef,
    t: buildTranslator(locale)
  };
};
const localeContextKey = /* @__PURE__ */ Symbol("localeContextKey");
const useLocale = (localeOverrides) => {
  const locale = localeOverrides || vue.inject(localeContextKey, vue.ref());
  return buildLocaleContext(vue.computed(() => locale.value || zhCn.default));
};

exports.buildLocaleContext = buildLocaleContext;
exports.buildTranslator = buildTranslator;
exports.localeContextKey = localeContextKey;
exports.translate = translate;
exports.useLocale = useLocale;
//# sourceMappingURL=index.js.map
