SetLocaleMiddleware class final

Picks the request's locale from ?lang= (or query) or the Accept-Language header, among supported, and makes it the locale of the request: trans, App.locale and validation messages follow it. Without a match the application locale stays.

middleware.use(const [SetLocaleMiddleware(supported: ['en', 'id'])]);
Implemented types

Constructors

SetLocaleMiddleware({required List<String> supported, String? query = 'lang'})
const

Properties

hashCode → int
The hash code for this object.
no setterinherited
query → String?
The query parameter that chooses the locale (null to ignore it).
final
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
supported → List<String>
final

Methods

handle(Request request, Next next) → Future<Response>
override
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() → String
A string representation of this object.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited

Static Methods

match(String? tag, List<String> supported) → String?
The entry of supported for tag (id-ID matches id_ID, then id), ignoring case; null when none fits.
negotiate(String? header, List<String> supported) → String?
The best of supported for an Accept-Language header (id-ID,id;q=0.9,en;q=0.8): highest quality first, q=0 excluded.