You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

38 lines
1.3 KiB

11 months ago
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
var vue = require('vue');
var get = require('lodash/get');
var en = require('../../locale/lang/en.js');
var index = require('../use-global-config/index.js');
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
var get__default = /*#__PURE__*/_interopDefaultLegacy(get);
const buildTranslator = (locale) => (path, option) => translate(path, option, vue.unref(locale));
const translate = (path, option, locale) => get__default["default"](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 useLocale = () => {
const locale = index.useGlobalConfig("locale");
return buildLocaleContext(vue.computed(() => locale.value || en["default"]));
};
exports.buildLocaleContext = buildLocaleContext;
exports.buildTranslator = buildTranslator;
exports.translate = translate;
exports.useLocale = useLocale;
//# sourceMappingURL=index.js.map