INNER CODE UNIT · TypeScript
detectFromRootParams
i18next/next-i18next · src/appRouter/server.ts:171
async function detectFromRootParams(config: NormalizedConfig): Promise<string | undefined> {
try {
const rootParams: Record<string, (() => Promise<unknown>) | undefined> = await import('next/root-params')
const value = await rootParams[config.localeParamName]?.()
if (typeof value !== 'string') return undefined
return findSupportedMatch(value, config.supportedLngs, config.nonExplicitSupportedLngs)
} catch {
return undefined
}
}
// Per-request language detection, deduplicated within a single React render
const detectLanguage = cache(async (config: NormalizedConfig): Promise<string> => {
const fromRoute = await detectFromRootParams(config)
if (fromRoute) return fromRoute
const headerList = await headers()
const fromHeader = headerList.get(config.headerName)