Interface LocaleResolver
-
public interface LocaleResolver
Locale resolvers are used to determine the locale of the current request and are discovered using Jakarta Contexts and Dependency Injection.
The Jakarta MVC implementation is required to resolve the locale for each request following this algorithm:
- Gather the set of all implementations of this interface available for injection via CDI.
- Sort the set of implementations using priorities in descending order. Locale resolvers
can be decorated with
Priority
to indicate their priority. If no priority is explicitly defined, the priority is assumed to be1000
. - Call the method
resolveLocale(LocaleResolverContext)
. If the resolver returns a valid locale, use this locale as the request locale. If the resolver returnsnull
, proceed with the next resolver in the ordered set.
Controllers, view engines and other components can access the resolved locale by calling
MvcContext.getLocale()
.The MVC implementation is required to provide a default locale resolver with a priority of
0
which uses theAccept-Language
request header to obtain the locale. If resolving the locale this way isn't possible, the default resolver must returnLocale.getDefault()
.- Since:
- 1.0
- Author:
- Christian Kaltepoth, Ivar Grimstad
- See Also:
LocaleResolverContext
,MvcContext.getLocale()
,Locale
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description Locale
resolveLocale(LocaleResolverContext context)
Resolve the locale of the current request given aLocaleResolverContext
.
-
-
-
Method Detail
-
resolveLocale
Locale resolveLocale(LocaleResolverContext context)
Resolve the locale of the current request given a
LocaleResolverContext
.If the implementation is able to resolve the locale for the request, the corresponding locale must be returned. If the implementation cannot resolve the locale, it must return
null
. In this case the resolving process will continue with the next resolver.- Parameters:
context
- the context needed for processing.- Returns:
- The resolved locale or
null
.
-
-