haven 0.1.5

Actix + React + Vite integration for server-rendered applications
Documentation
import { useLocale } from "./framework.jsx";
const runtimeTranslate = globalThis.__RUNTIME_I18N__?.t;

function interpolate(template, params) {
  return String(template).replaceAll(/\{([^}]+)\}/g, (_, key) => {
    const value = params?.[key.trim()];
    return value == null ? `{${key}}` : String(value);
  });
}

export function t(key, params = {}, locale) {
  if (runtimeTranslate) {
    return runtimeTranslate(key, params, locale);
  }

  return interpolate(key, params);
}

export function useI18n() {
  const locale = useLocale();

  return {
    locale,
    t(key, params = {}, explicitLocale) {
      return t(key, params, explicitLocale ?? locale);
    },
  };
}

if (!globalThis.__RUNTIME_I18N__) {
  globalThis.__RUNTIME_I18N__ = {
    t,
  };
}