Files

37 lines
1.6 KiB
TypeScript

import type { I18nConfig } from './types.js';
/** Cookie name the template uses to persist a visitor's locale choice. */
/**
* Cookie name for the persisted locale choice. Uses NEXT_LOCALE — the convention
* Next.js and its i18n ecosystem expect — so the cookie is interoperable with
* other libraries that read the active locale (instead of a plugin-specific
* name). Written only under functional consent; cleared when that consent is
* withdrawn (see consent cookieMap).
*/
export declare const LOCALE_COOKIE_NAME = "NEXT_LOCALE";
type NegotiateLocaleArgs = {
/** Raw Accept-Language header value */
acceptLanguage?: null | string;
config: I18nConfig;
/** Value of the locale cookie, if present (from LOCALE_COOKIE_NAME) */
cookieLocale?: null | string;
};
/**
* Resolves which locale to serve, in priority order:
* 1. Cookie (explicit prior choice)
* 2. Accept-Language header (best match against configured locales)
* 3. Configured default locale
*
* Pure function — the template feeds it request data and acts on the result
* (redirect, cookie set). No Next.js or request objects here.
*/
export declare function negotiateLocale({ acceptLanguage, config, cookieLocale, }: NegotiateLocaleArgs): string;
/**
* Parses an Accept-Language header and returns the best-matching configured
* locale, or undefined if none match.
*
* Matches on the primary subtag (e.g. "en-US" matches configured "en"),
* respecting the header's quality-value ordering.
*/
export declare function matchAcceptLanguage(acceptLanguage: null | string | undefined, config: I18nConfig): string | undefined;
export {};