function format(template, params) {
  if (!params) return template;
  return template.replace(/\{\{(\w+)\}\}|\{(\w+)\}/g, (match, doubleKey, singleKey) => {
    const key = doubleKey ?? singleKey;
    if (!key) return match;
    const value = params[key];
    if (value === void 0) return match;
    return String(value);
  });
}
function createTranslator(dict) {
  const translator = ((key, fallbackOrParams, params) => {
    let fallback;
    let resolvedParams;
    if (typeof fallbackOrParams === "string") {
      fallback = fallbackOrParams;
      resolvedParams = params;
    } else {
      resolvedParams = fallbackOrParams;
    }
    const template = dict[key] ?? fallback ?? key;
    return format(template, resolvedParams);
  });
  return translator;
}
function translateWithFallback(t, key, fallback, params) {
  const value = params ? t(key, params) : t(key);
  if (value !== key) return value;
  if (fallback === void 0) return key;
  return format(fallback, params);
}
function createTranslatorWithFallback(translate) {
  return (key, fallback, params) => translateWithFallback(translate, key, fallback, params);
}
function createFallbackTranslator(dict) {
  const t = createTranslator(dict);
  return (key, fallback, params) => translateWithFallback(t, key, fallback, params);
}
export {
  createFallbackTranslator,
  createTranslator,
  createTranslatorWithFallback,
  translateWithFallback
};
//# sourceMappingURL=translate.js.map
