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:

    1. Gather the set of all implementations of this interface available for injection via CDI.
    2. 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 be 1000.
    3. Call the method resolveLocale(LocaleResolverContext). If the resolver returns a valid locale, use this locale as the request locale. If the resolver returns null, 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 the Accept-Language request header to obtain the locale. If resolving the locale this way isn't possible, the default resolver must return Locale.getDefault().

    Since:
    1.0
    Author:
    Christian Kaltepoth, Ivar Grimstad
    See Also:
    LocaleResolverContext, MvcContext.getLocale(), Locale
    • 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.