public static Map<String, String> getLocalizedValuesMap(String localeBundle) { if (StringUtils.isNotEmpty(localeBundle)) { Properties localeProperties = loadProperties(localeBundle); if (localeProperties != null) { Map<String, String> map = new HashMap<>(); for (Map.Entry<Object, Object> entry : localeProperties.entrySet()) { map.put((String) entry.getKey(), (String) entry.getValue()); } return map; } } return Collections.emptyMap(); }
public static String convertFromSimpleKeyLocales(String enumValue, String localeBundle) { Properties result = new Properties(); Properties properties = loadProperties(localeBundle); if (properties != null) { for (Map.Entry<Object, Object> entry : properties.entrySet()) { String key = (String) entry.getKey(); result.put(key + "/" + enumValue, entry.getValue()); } } return convertPropertiesToString(result); }
public static String convertToSimpleKeyLocales(String localeBundle) { Properties result = new Properties(); Properties properties = loadProperties(localeBundle); if (properties != null) { for (Map.Entry<Object, Object> entry : properties.entrySet()) { String key = (String) entry.getKey(); key = key.substring(0, key.indexOf("/")); result.put(key, entry.getValue()); } } return convertPropertiesToString(result); }
public static String getLocalizedName(String localeBundle) { Locale locale = AppBeans.get(UserSessionSource.class).getLocale(); String localeName = null; if (StringUtils.isNotEmpty(localeBundle)) { Properties localeProperties = loadProperties(localeBundle); if (localeProperties != null) { String key = locale.getLanguage(); if (StringUtils.isNotEmpty(locale.getCountry())) key += "_" + locale.getCountry(); if (localeProperties.containsKey(key)) localeName = (String) localeProperties.get(key); } } return localeName; }
public static String getLocalizedEnumeration(String enumerationValues, String localeBundle) { String result = null; if (StringUtils.isNotEmpty(localeBundle)) { Properties localeProperties = loadProperties(localeBundle); if (localeProperties != null) { Locale locale = AppBeans.get(UserSessionSource.class).getLocale(); String key = locale.getLanguage(); if (StringUtils.isNotEmpty(locale.getCountry())) { key += "_" + locale.getCountry(); } List<String> enumValues = new ArrayList<>(); String[] enumerationValuesArray = enumerationValues.split(","); Map<String, String> localizedValuesMap = LocaleHelper.getLocalizedValuesMap(localeBundle); for (String value : enumerationValuesArray) { String resultValue = localizedValuesMap.getOrDefault(key + "/" + value, value); enumValues.add(resultValue); } result = Joiner.on(",").join(enumValues); } } return result; }