import { RedirectFunction, RouterContextProvider } from 'react-router'; import { I18n } from '@lingui/core'; import { R as RouteLocale } from '../shared/lingui-react-router.DWN5Xbd0.cjs'; import 'react'; type ChangeLocaleServerFunction = (locale: string | undefined) => Response; /** * Server-side i18n context. */ type I18nRequestContext = Omit & { /** The internationalization processing object, which manages locale-specific content and configurations. */ i18n: I18n; /** The translation function bound to the current i18n instance. */ _: I18n["_"]; /** The URL object for the current request, representing its full path and query parameters. */ url: URL; /** * Function to redirect to a different locale while preserving the current locale prefix. * * @param to The target URL or path to redirect to, without the locale prefix * @param init Optional redirect initialization options * @returns A redirect response to the specified URL with the current locale prefix */ redirect: RedirectFunction; /** * Change the locale and redirect to the same path. * * @param locale The new locale code * @returns A redirect response to the same path with the new locale prefix */ changeLocale: ChangeLocaleServerFunction; }; /** * Hook to access the server-side i18n context. Use only in loaders and actions. * * @throws {Error} If used outside a localeMiddleware context * @returns {I18nRequestContext} The server-side i18n context object containing: * - i18n: The internationalization processing object * - url: The URL object for the current request * - requestLocale: The locale explicitly requested by the client, if any * - requestPathname: The pathname of the current request * - pathnamePrefix: The pathname prefix for the current locale (e.g. "/en") * - _: The translation function bound to the current i18n instance * - redirect: Function to redirect to a different locale while preserving the current locale prefix */ declare function useLinguiServer(context: Readonly): I18nRequestContext; type MiddlewareFunctionArgs = { request: Request; context: Readonly; params: unknown; }; /** * Locale middleware implementation. Determines the locale from the URL or the * Accept-Language header, initializes i18n, and runs the request with a LocaleServerContext. * * Use `useLinguiServer` in loaders and actions to access the server-side i18n context. * * @param request The request object * @param context The router context * @param params The route parameters * @param next The next middleware function * @returns The response from the next middleware or route handler */ declare function localeMiddleware({ request, context, params }: MiddlewareFunctionArgs, next: () => Promise): Promise; /** * @deprecated Use I18nRequestContext instead. Will be removed in 2.0.0 */ type I18nRouterContext = I18nRequestContext; export { localeMiddleware, useLinguiServer }; export type { I18nRequestContext, I18nRouterContext };