zhangyong
2023-08-22 1353e87cb21a4032d585d7404bae9042f2ebcf08
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
'use strict';
 
Object.defineProperty(exports, '__esModule', { value: true });
 
var vue = require('vue');
var lodashUnified = require('lodash-unified');
var en = require('../../locale/lang/en.js');
 
const buildTranslator = (locale) => (path, option) => translate(path, option, vue.unref(locale));
const translate = (path, option, locale) => lodashUnified.get(locale, path, path).replace(/\{(\w+)\}/g, (_, key) => {
  var _a;
  return `${(_a = option == null ? void 0 : option[key]) != null ? _a : `{${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 = Symbol("localeContextKey");
const useLocale = (localeOverrides) => {
  const locale = localeOverrides || vue.inject(localeContextKey, vue.ref());
  return buildLocaleContext(vue.computed(() => locale.value || en["default"]));
};
 
exports.buildLocaleContext = buildLocaleContext;
exports.buildTranslator = buildTranslator;
exports.localeContextKey = localeContextKey;
exports.translate = translate;
exports.useLocale = useLocale;
//# sourceMappingURL=index.js.map