public interface LocalizedPopulator
LocalizedPopulator is used to retrieve the languages supported by the current base store and to
populate localized attributes.| Modifier and Type | Method and Description |
|---|---|
default java.lang.String |
getLanguage(java.util.Locale locale)
Returns the language for that specific locale.
|
<T> void |
populate(java.util.function.BiConsumer<java.util.Locale,T> consumer,
java.util.function.Function<java.util.Locale,T> getter)
Bi-directional method to populate the localized attributes.
|
default <T> java.util.Map<java.lang.String,T> |
populateAsMapOfLanguages(java.util.function.Function<java.util.Locale,T> getter)
Default implementation for populating a
Map<String, T applying the function getter on each locale. |
default <T> java.util.Map<java.util.Locale,T> |
populateAsMapOfLocales(java.util.function.Function<java.lang.String,T> getter)
Default implementation for populating a
Map<Locale, T applying the function getter on each language ISO
code. |
<T> void populate(java.util.function.BiConsumer<java.util.Locale,T> consumer,
java.util.function.Function<java.util.Locale,T> getter)
getter function,
and also populate localized Maps by reading content from a localized data model.
This method will iterate over all locales (Locale) available at the execution time.
For each locale, it will execute the function getter to get the localized value that may
be coming from different sources (see examples bellow).
The result of the getter function will then be used on the BiConsumer setter function.
Examples of its usage:
Populate a Map<String, String> from a localized model
final Map<String, String> map = new HashMap<>();
getLocalizedPopulator().populate(
(locale, value) -> map.put(getLocalizedPopulator().getLanguage(locale), value),
(locale) -> source.getSomeLocalizedField(locale)
);
* Populate an ItemModel from a localized Map<String, String>
// source.getTitle() returns Map<String, String>
Optional.ofNullable(source.getTitle())
.ifPresent(title ->
getLocalizedPopulator()
.populate((locale, value) -> target.setTitle(value, locale),
(locale) -> title.get(getLocalizedPopulator().getLanguage(locale))));
consumer - A BiConsumer function that will accept the Locale and the Value extracted from the getter function.getter - A Function that will be applied to get the localized value for a given Locale.default <T> java.util.Map<java.lang.String,T> populateAsMapOfLanguages(java.util.function.Function<java.util.Locale,T> getter)
Map<String, T applying the function getter on each locale.T - the type of the object that is put as a value in the returned map.getter - A Function that will be applied to each Locale.default <T> java.util.Map<java.util.Locale,T> populateAsMapOfLocales(java.util.function.Function<java.lang.String,T> getter)
Map<Locale, T applying the function getter on each language ISO
code.T - the type of the object that is put as a value in the returned map.getter - A Function that will be applied to each language ISO codedefault java.lang.String getLanguage(java.util.Locale locale)
Locale.toString().
More specialized implementations should opt to return the format in which the data
can be correctly translated in other domains.locale - the locale we want to get the language from.Copyright © 2018 SAP SE. All Rights Reserved.