Package org.keycloak.services.util
Class LocaleUtil
java.lang.Object
org.keycloak.services.util.LocaleUtil
- Author:
 - Marek Posolda, Daniel Fesenmeyer
 
- 
Method Summary
Modifier and TypeMethodDescriptionstatic PropertiesenhancePropertiesWithRealmLocalizationTexts(RealmModel realm, Locale locale, Map<Locale, Properties> themeMessages) Enhance the properties from a theme with realm localization texts.static LocalegetParentLocale(Locale locale) Returns the parent locale of the givenlocale.static Map<Locale,Properties> getRealmLocalizationTexts(RealmModel realm, Locale locale) static PropertiesmergeGroupedMessages(Locale locale, Map<Locale, Properties> messages) Merge the given (locale-)grouped messages into one instance ofProperties, applicable for the givenlocale.static PropertiesmergeGroupedMessages(Locale locale, Map<Locale, Properties> firstMessages, Map<Locale, Properties> secondMessages) Merge the given (locale-)grouped messages into one instance ofProperties, applicable for the givenlocale.static voidprocessLocaleParam(KeycloakSession session, RealmModel realm, AuthenticationSessionModel authSession)  
- 
Method Details
- 
processLocaleParam
public static void processLocaleParam(KeycloakSession session, RealmModel realm, AuthenticationSessionModel authSession)  - 
getParentLocale
Returns the parent locale of the givenlocale. If the locale just contains a language (e.g. "de"), returns the fallback locale "en". For "en" no parent exists,nullis returned.- Parameters:
 locale- the locale- Returns:
 - the parent locale, may be 
null 
 - 
mergeGroupedMessages
Merge the given (locale-)grouped messages into one instance ofProperties, applicable for the givenlocale.- Parameters:
 locale- the localemessages- 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 ofProperties, applicable for the givenlocale.The priority of the messages is as follows (abbreviations: F = firstMessages, S = secondMessages):
- F <language-region-variant>
 - S <language-region-variant>
 - F <language-region>
 - S <language-region>
 - F <language>
 - S <language>
 - F en
 - S en
 
Example for the message priority for locale "de-CH-1996" (language "de", region "CH", variant "1996):
- F de-CH-1996
 - S de-CH-1996
 - F de-CH
 - S de-CH
 - F de
 - S de
 - F en
 - S en
 
- Parameters:
 locale- the localefirstMessages- the first (locale-)grouped messages, having higher priority (per locale) thansecondMessagessecondMessages- may benull, the second (locale-)grouped messages, having lower priority (per locale) thanfirstMessages- 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 usedlocale- the locale for which the relevant texts should be retrievedthemeMessages- the theme messages, which should be enhanced and maybe overwritten- Returns:
 - the enhanced properties
 
 - 
getRealmLocalizationTexts
 
 -