Skip to content

Never stop coding. Free MIT AI gateway: one endpoint, 375 providers (150+ free), 1,400+ models Kimi, Claude, GPT, Gemini, GLM, DeepSeek, MiniMax. Works with Claude Code, Codex, Cursor, OpenCode, Cline & Copilot. Quota-aware auto-fallback, RTK+Caveman compression saves 15-95% tokens, MCP/A2A, Desktop/PWA. Built by 900+ contributors

1.3 KB
Raw Blame
import { NextIntlClientProvider } from "next-intl";
import { getMessages } from "next-intl/server";

import { normalizeComplianceEventTypes } from "@/i18n/request";
import { pickMessages } from "@/i18n/pickMessages";

/**
 * Server component that re-scopes the client i18n catalog for a route
 * subtree: loads the full merged catalog (server-side only) and serializes
 * just the given namespaces into the flight payload.
 *
 * next-intl's nested client providers REPLACE the message set for their
 * subtree (they do not merge), so every set passed here must be complete
 * for everything rendered below it — the generated maps always include the
 * dashboard chrome namespaces alongside the section's own.
 *
 * Never call this without `namespaces` from the generated map
 * (src/i18n/routeNamespaces.generated.json); omitting the messages prop on
 * any NextIntlClientProvider makes next-intl fall back to embedding the
 * whole catalog again.
 */

interface SectionI18nProviderProps {
  namespaces: readonly string[];
  children: React.ReactNode;
}

export async function SectionI18nProvider({ namespaces, children }: SectionI18nProviderProps) {
  const messages = normalizeComplianceEventTypes(
    pickMessages((await getMessages()) as Record<string, unknown>, namespaces)
  );
  return <NextIntlClientProvider messages={messages}>{children}</NextIntlClientProvider>;
}