import "server-only" import { createIntl, createIntlCache } from "@formatjs/intl" import { Lang } from "@/constants/languages" import { getLang } from "@/i18n/serverContext" import type { IntlShape } from "react-intl" const cache = createIntlCache() const instances: Partial> = {} export async function getMessages(lang: Lang): Promise> { return (await import(`./dictionaries/${lang}.json`)).default } export async function getIntl(options?: { lang: Lang | undefined }) { const lang = options?.lang || getLang() if (!instances[lang]) { const messages = await getMessages(lang) instances[lang] = createIntl( { defaultLocale: Lang.en, locale: lang, messages, }, cache ) } return instances[lang] }