Class MultiString

java.lang.Object
java.util.AbstractMap<K,V>
java.util.HashMap<String,String>
org.pipservices3.commons.data.MultiString
All Implemented Interfaces:
Serializable, Cloneable, Map<String,String>

public class MultiString extends HashMap<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:
  • Constructor Details

    • MultiString

      public MultiString()
    • MultiString

      public MultiString(Map<?,?> map)
      Creates a new MultiString object and initializes it with values.
      Parameters:
      map - a map with language-text pairs.
  • Method Details

    • get

      public String get(String language)
      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

      public List<String> getLanguages()
      Gets all languages stored in this MultiString object,
      Returns:
      a list with language codes.
    • put

      public void put(String language, Object value)
      Puts a new translation for the specified language.
      Parameters:
      language - a language two-symbol code.
      value - a new translation for the specified language.
    • append

      public void append(Map<?,?> map)
      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

      public static MultiString fromValue(Map<?,?> value)
      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

      public static MultiString fromTuples(Object... tuples)
      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

      public static MultiString fromTuplesArray(Object[] tuples)
      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.