Skip to content

Commit

Permalink
When getting locale message, default locale to LocaleContextHolder wh…
Browse files Browse the repository at this point in the history
…en locale is null (geonetwork#7516)
  • Loading branch information
ianwallen authored Nov 30, 2023
1 parent 255e5d2 commit d77409e
Showing 1 changed file with 4 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import org.fao.geonet.utils.Log;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.BeanFactoryAnnotationUtils;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.context.support.ResourceBundleMessageSource;

import com.google.common.collect.BiMap;
Expand All @@ -57,16 +58,16 @@ public static String getMessageForLocale(String messageKey, Locale locale, Strin
*
* @param messageKey message key to use when retrieving the value from the properties file.
* @param args Argument that may be supplied to the messagekey string
* @param locale locale to use when getting the message key
* @param locale locale to use when getting the message key. If null then it will default to locale context holder.
* @param resourceBundleBeanQualifier resource bundle qualifier to use when getting ResourceBundleMessageSource bean
* @return message
*/

public static String getMessageForLocale(String messageKey, Object[] args, Locale locale, String resourceBundleBeanQualifier) {
if (!StringUtils.isEmpty(messageKey) && locale !=null) {
if (!StringUtils.isEmpty(messageKey)) {
ResourceBundleMessageSource resourceBundleMessageSource = getResourceBundleMessageSource(resourceBundleBeanQualifier);
if (resourceBundleMessageSource != null) {
return resourceBundleMessageSource.getMessage(messageKey, args, locale);
return resourceBundleMessageSource.getMessage(messageKey, args, locale == null ? LocaleContextHolder.getLocale() : locale);
}
}
// If we could not find the ResourceBundleMessageSource or the messageKey was in an invalid format then lets return the original key as the message.
Expand Down

0 comments on commit d77409e

Please sign in to comment.