INNER CODE UNIT · TypeScript
createState
i18next/next-i18next · src/appRouter/server.ts:22
function createState(userConfig: I18nConfig): ServerState {
return { config: normalizeConfig(userConfig), instance: null, instancePromise: null }
}
// The default state (initServerI18next + module-level getT) is keyed on globalThis, so a
// second copy of this module in the same process — another bundling layer such as a
// Route Handler, or the CJS build next to the ESM one — sees the same initialization.
const GLOBAL_KEY = Symbol.for('next-i18next.server')
const shared: { state: ServerState | null } = ((globalThis as any)[GLOBAL_KEY] ??= { state: null })
function getState(): ServerState {
if (!shared.state) {
throw new Error(
'next-i18next: server i18n is not initialized. Call initServerI18next(config) before the first ' +
'getT() in this process, or use createServerI18next(config) and import getT from its result, ' +
'which needs no initialization.'
)
}