Table of Contents

TLocaleMiddleware Class

Middleware that performs locale negotiation based on the Accept-Language HTTP header.

Remarks

This middleware parses the Accept-Language header from incoming requests and determines the best matching locale. The selected locale is stored in the request context and can be retrieved using Context.Item<ILocale>. The middleware also sets the Content-Language response header to indicate the locale used for the response.

Syntax

Unit: Sparkle.Middleware.Locale

TLocaleMiddleware = class(THttpServerMiddleware, IHttpServerMiddleware);

Properties

Name Description
DefaultLocale The default locale to use when no Accept-Language header is present or no matching locale is found.
OnAcceptLocale Callback invoked for each locale candidate during negotiation.
OnGetDefaultLocale Callback invoked to dynamically determine the default locale.