Class 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) Deprecated, for removal: This API element is subject to removal in a future version.static LocalegetParentLocale(Locale locale, RealmModel realm) Returns the parent locale of the givenlocale.static Map<Locale,Properties> getRealmLocalizationTexts(RealmModel realm, Locale locale) static PropertiesmergeGroupedMessages(RealmModel realm, Locale locale, Map<Locale, Properties> messages) Merge the given (locale-)grouped messages into one instance ofProperties, applicable for the givenlocale.static PropertiesmergeGroupedMessages(RealmModel realm, 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) static LocaleresolveSupportedLocale(RealmModel realm, Theme theme, String localeString) Resolves a language tag received from a client to a locale the server is prepared to serve messages for.
-
Method Details
-
processLocaleParam
public static void processLocaleParam(KeycloakSession session, RealmModel realm, AuthenticationSessionModel authSession) -
resolveSupportedLocale
Resolves a language tag received from a client to a locale the server is prepared to serve messages for.The requested tag is matched against the locales declared by the theme, the locales supported by the realm and the realm default locale. Only a locale from that bounded, server-controlled set is ever returned, so a client cannot introduce arbitrary locales into the caches which are keyed by locale. A tag without a match resolves to the realm default locale, or to
Locale.ENGLISH, rather than being rejected, so that clients still requesting a locale which has meanwhile been removed from the realm keep receiving usable content.- Parameters:
realm- the realmtheme- the theme whose messages are looked up, may benulllocaleString- the requested language tag, may benull- Returns:
- a supported locale, never
null
-
getParentLocale
Deprecated, for removal: This API element is subject to removal in a future version.usegetParentLocale(Locale, RealmModel)instead.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
-
getParentLocale
Returns the parent locale of the givenlocale. If the locale just contains a language (e.g. "de"), returns the fallback default locale of the realm or if that does not exist "en". For "en" no parent exists,nullis returned.- Returns:
- the parent locale, may be
null
-
mergeGroupedMessages
public static Properties mergeGroupedMessages(RealmModel realm, Locale locale, Map<Locale, Properties> messages) 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(RealmModel realm, 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(RealmModel, 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
-
getParentLocale(Locale, RealmModel)instead.