Class LocaleUtil

java.lang.Object
org.keycloak.services.util.LocaleUtil

public class LocaleUtil extends Object
Author:
Marek Posolda, Daniel Fesenmeyer
  • Method Details

    • processLocaleParam

      public static void processLocaleParam(KeycloakSession session, RealmModel realm, AuthenticationSessionModel authSession)
    • getParentLocale

      public static Locale getParentLocale(Locale locale)
      Returns the parent locale of the given locale. If the locale just contains a language (e.g. "de"), returns the fallback locale "en". For "en" no parent exists, null is returned.
      Parameters:
      locale - the locale
      Returns:
      the parent locale, may be null
    • mergeGroupedMessages

      public static Properties mergeGroupedMessages(Locale locale, Map<Locale,Properties> messages)
      Merge the given (locale-)grouped messages into one instance of Properties, applicable for the given locale.
      Parameters:
      locale - the locale
      messages - the (locale-)grouped messages
      Returns:
      the merged properties
      See Also:
    • mergeGroupedMessages

      public static Properties mergeGroupedMessages(Locale locale, Map<Locale,Properties> firstMessages, Map<Locale,Properties> secondMessages)
      Merge the given (locale-)grouped messages into one instance of Properties, applicable for the given locale.

      The priority of the messages is as follows (abbreviations: F = firstMessages, S = secondMessages):

      1. F <language-region-variant>
      2. S <language-region-variant>
      3. F <language-region>
      4. S <language-region>
      5. F <language>
      6. S <language>
      7. F en
      8. S en

      Example for the message priority for locale "de-CH-1996" (language "de", region "CH", variant "1996):

      1. F de-CH-1996
      2. S de-CH-1996
      3. F de-CH
      4. S de-CH
      5. F de
      6. S de
      7. F en
      8. S en
      Parameters:
      locale - the locale
      firstMessages - the first (locale-)grouped messages, having higher priority (per locale) than secondMessages
      secondMessages - may be null, the second (locale-)grouped messages, having lower priority (per locale) than firstMessages
      Returns:
      the merged properties
      See Also:
    • enhancePropertiesWithRealmLocalizationTexts

      public static Properties enhancePropertiesWithRealmLocalizationTexts(RealmModel realm, Locale locale, Map<Locale,Properties> themeMessages)
      Enhance the properties from a theme with realm localization texts. Realm localization texts take precedence over the theme properties, but only when defined for the same locale. In general, texts for a more specific locale take precedence over texts for a less specific locale.

      For implementation details, see mergeGroupedMessages(Locale, Map, Map).

      Parameters:
      realm - the realm from which the localization texts should be used
      locale - the locale for which the relevant texts should be retrieved
      themeMessages - the theme messages, which should be enhanced and maybe overwritten
      Returns:
      the enhanced properties
    • getRealmLocalizationTexts

      public static Map<Locale,Properties> getRealmLocalizationTexts(RealmModel realm, Locale locale)