Package org.pipservices3.commons.data
Class MultiString
- All Implemented Interfaces:
Serializable
,Cloneable
,Map<String,
String>
An object that contains string translations for multiple languages.
Language keys use two-letter codes like: 'en', 'sp', 'de', 'ru', 'fr', 'pr'.
When translation for specified language does not exists it defaults to English ('en').
When English does not exists it falls back to the first defined language.
### Example ###
MultiString values = MultiString.fromTuples(
"en", "Hello World!",
"ru", "Привет мир!"
);
String value1 = values.get("ru"); // Result: "Привет мир!"
String value2 = values.get("pt"); // Result: "Hello World!"
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class java.util.AbstractMap
AbstractMap.SimpleEntry<K extends Object,
V extends Object>, AbstractMap.SimpleImmutableEntry<K extends Object, V extends Object> -
Constructor Summary
ConstructorDescriptionMultiString
(Map<?, ?> map) Creates a new MultiString object and initializes it with values. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Appends a map with language-translation pairs.static MultiString
fromTuples
(Object... tuples) Creates a new MultiString object from language-translation pairs (tuples).static MultiString
fromTuplesArray
(Object[] tuples) Creates a new MultiString object from language-translation pairs (tuples) specified as array.static MultiString
Creates a new MultiString object from a value that contains language-translation pairs.Gets a string translation by specified language.Gets all languages stored in this MultiString object,int
length()
Returns the number of translations stored in this MultiString object.void
Puts a new translation for the specified language.Methods inherited from class java.util.HashMap
clear, clone, compute, computeIfAbsent, computeIfPresent, containsKey, containsValue, entrySet, forEach, get, getOrDefault, isEmpty, keySet, merge, put, putAll, putIfAbsent, remove, remove, replace, replace, replaceAll, size, values
Methods inherited from class java.util.AbstractMap
equals, hashCode, toString
-
Constructor Details
-
MultiString
public MultiString() -
MultiString
Creates a new MultiString object and initializes it with values.- Parameters:
map
- a map with language-text pairs.
-
-
Method Details
-
get
Gets a string translation by specified language. When language is not found it defaults to English ('en'). When English is not found it takes the first value.- Parameters:
language
- a language two-symbol code.- Returns:
- a translation for the specified language or default translation.
-
getLanguages
Gets all languages stored in this MultiString object,- Returns:
- a list with language codes.
-
put
Puts a new translation for the specified language.- Parameters:
language
- a language two-symbol code.value
- a new translation for the specified language.
-
append
Appends a map with language-translation pairs.- Parameters:
map
- the map with language-translation pairs.
-
length
public int length()Returns the number of translations stored in this MultiString object.- Returns:
- the number of translations.
-
fromValue
Creates a new MultiString object from a value that contains language-translation pairs.- Parameters:
value
- the value to initialize MultiString.- Returns:
- a MultiString object.
- See Also:
-
fromTuples
Creates a new MultiString object from language-translation pairs (tuples).- Parameters:
tuples
- an array that contains language-translation tuples.- Returns:
- a MultiString Object.
- See Also:
-
fromTuplesArray
Creates a new MultiString object from language-translation pairs (tuples) specified as array.- Parameters:
tuples
- an array that contains language-translation tuples.- Returns:
- a MultiString Object.
-