import en from "@/messages/en.json";
import fr from "@/messages/fr.json";

const catalogs = { en, fr } as const;

export type Locale = keyof typeof catalogs;

export function getMessages(locale: string | undefined | null) {
  return catalogs[locale as Locale] ?? catalogs.en;
}

export function formatMessage(template: string, vars: Record<string, string | number>) {
  return template.replace(/\{(\w+)\}/g, (_, key) => String(vars[key] ?? ""));
}
