"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.translations = exports.translate = exports.t = exports.createTranslator = void 0;
var _template = _interopRequireDefault(require("lodash/template"));
var _en = _interopRequireDefault(require("./en"));
var _zh = _interopRequireDefault(require("./zh"));
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
const translations = exports.translations = {
  zh: _zh.default,
  en: _en.default
};
const replace = (t2, data = {}) => {
  try {
    const compiled = (0, _template.default)(t2, {
      interpolate: /{([\s\S]+?)}/g,
      escape: /{([\s\S]+?)}/g
    });
    return compiled(data);
  } catch (e) {
    console.error(`Error evaluating template: ${t2}`, e);
    return "";
  }
};
const createTranslator = ({
  fallbackLocale = "en"
}, langs = translations) => {
  return (key, locale = fallbackLocale, data = {}) => {
    if (!langs[locale] || !langs[locale][key]) {
      if (fallbackLocale && langs[fallbackLocale]?.[key]) {
        return replace(langs[fallbackLocale]?.[key], data);
      }
      return key;
    }
    return replace(langs[locale][key], data);
  };
};
exports.createTranslator = createTranslator;
const translate = exports.translate = createTranslator({
  fallbackLocale: "en"
});
const t = exports.t = translate;