public String getLocalizedValues() { Properties properties = new Properties(); for (CategoryAttributeEnumValue enumValue : enumValuesDs.getItems()) { properties.putAll(LocaleHelper.getLocalizedValuesMap(enumValue.getLocalizedValues())); } enumerationLocales = LocaleHelper.convertPropertiesToString(properties); return enumerationLocales; }
public Map<String, Object> getLocalizedEnumerationMap() { String enumeration = getEnumeration(); String[] values = StringUtils.split(enumeration, ','); Map<String, Object> map = new LinkedHashMap<>(); for (String s : values) { map.put(LocaleHelper.getEnumLocalizedValue(s, enumerationLocales), s); } return map; } }
public static boolean isLocalizedValueDefined(String localeBundle) { return getLocalizedName(localeBundle) != null; } }
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); }
CategoryAttributeEnumValue prevItem = e.getPrevItem(); String changedValues = LocaleHelper.convertFromSimpleKeyLocales(prevItem.getValue(), localizedFrame.getValue()); Map<String, String> changedValuesMap = LocaleHelper.getLocalizedValuesMap(changedValues); Map<String, String> itemValuesMap = LocaleHelper.getLocalizedValuesMap(prevItem.getLocalizedValues()); String localizedValues = e.getItem().getLocalizedValues() == null ? "" : LocaleHelper.convertToSimpleKeyLocales(e.getItem().getLocalizedValues()); localizedFrame.setValue(localizedValues);
column.setCaption(LocaleHelper.isLocalizedValueDefined(attribute.getLocaleNames()) ? attribute.getLocaleName() : StringUtils.capitalize(attribute.getName())); LocaleHelper.getEnumLocalizedValue((String) value, attribute.getEnumerationLocales()) );
protected String getColumnCaption(Object columnId, Column column) { String caption = column.getCaption(); if (caption != null) { return caption; } if (!(columnId instanceof MetaPropertyPath)) { return StringUtils.capitalize(getColumnCaption(columnId)); } MetaPropertyPath mpp = (MetaPropertyPath) columnId; MetaProperty metaProperty = mpp.getMetaProperty(); if (DynamicAttributesUtils.isDynamicAttribute(metaProperty)) { CategoryAttribute categoryAttribute = DynamicAttributesUtils.getCategoryAttribute(metaProperty); if (LocaleHelper.isLocalizedValueDefined(categoryAttribute.getLocaleNames())) { return categoryAttribute.getLocaleName(); } caption = StringUtils.capitalize(categoryAttribute.getName()); } else { caption = StringUtils.capitalize(getColumnCaption(columnId)); } return caption; }
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; }
public void setValue(String localeBundle) { if (localeBundle == null || textFieldMap == null) { return; } Map<String, String> localizedNamesMap = LocaleHelper.getLocalizedValuesMap(localeBundle); for (Map.Entry<Locale, TextField> textFieldEntry : textFieldMap.entrySet()) { String keyLocale = textFieldEntry.getKey().toString(); textFieldEntry.getValue().setValue(localizedNamesMap.get(keyLocale)); } }
protected String buildLocalizedValuesForEnumValue(String enumValue, Map<String, String> localizedValues) { Properties result = new Properties(); for (Map.Entry<String, String> entry : localizedValues.entrySet()) { String key = entry.getKey(); key = key.substring(key.indexOf("/") + 1); if (key.equals(enumValue)) { result.put(entry.getKey(), entry.getValue()); } } return LocaleHelper.convertPropertiesToString(result); }
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 String getEnumerationLocale() { enumerationLocale = LocaleHelper.getLocalizedEnumeration(enumeration, enumerationLocales); if (enumerationLocale == null) { enumerationLocale = enumeration; } return enumerationLocale; }
public void commit() { if (!enumValuesTable.getSelected().isEmpty()) { CategoryAttributeEnumValue enumValue = enumValuesTable.getSelected().iterator().next(); enumValue.setLocalizedValues( LocaleHelper.convertFromSimpleKeyLocales(enumValue.getValue(), localizedFrame.getValue()) ); } enumValuesDs.commit(); close(Window.COMMIT_ACTION_ID); }
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); }
CategoryAttribute categoryAttribute = DynamicAttributesUtils.getCategoryAttribute(metaProperty); columnCaption = LocaleHelper.isLocalizedValueDefined(categoryAttribute.getLocaleNames()) ? categoryAttribute.getLocaleName() : StringUtils.capitalize(categoryAttribute.getName());
public static String getEnumLocalizedValue(String enumValue, String localeBundle) { if (enumValue == null) { return null; } if (localeBundle == null) { return enumValue; } Map<String, String> map = getLocalizedValuesMap(localeBundle); Locale locale = AppBeans.get(UserSessionSource.class).getLocale(); String key = locale.getLanguage(); if (StringUtils.isNotEmpty(locale.getCountry())) { key += "_" + locale.getCountry(); } String result = map.getOrDefault(key + "/" + enumValue, ""); return Objects.equals(result, "") ? enumValue : result; }
public String getValue() { Properties properties = new Properties(); for (Map.Entry<Locale, TextField> entry : textFieldMap.entrySet()) { if (!entry.getValue().getRawValue().isEmpty()) { properties.setProperty(entry.getKey().toString(), entry.getValue().getRawValue()); } } return LocaleHelper.convertPropertiesToString(properties); }
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 String getLocaleName() { localeName = LocaleHelper.getLocalizedName(localeNames); if (localeName == null) { localeName = name; } return localeName; } }
columnCaption = LocaleHelper.isLocalizedValueDefined(categoryAttribute.getLocaleNames()) ? categoryAttribute.getLocaleName() : StringUtils.capitalize(categoryAttribute.getName());