import type { I18n } from "@lingui/core";
import { createI18n, resolveLocale } from "@/lib/i18n";

/**
 * Server-side i18n instance for the requester's locale, for use with
 * msg`` descriptors + i18n._() when localizing API route error strings.
 * Pass the SuperTokens user metadata (or undefined/null for anonymous
 * requests) — falls back to DEFAULT_LOCALE when no locale is set.
 */
export function localizedFor(metadata?: { locale?: string } | null): I18n {
  return createI18n(resolveLocale(metadata?.locale));
}
